Path: blob/main/components/gitpod-protocol/go/user_test.go
2498 views
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package protocol56import "testing"78func TestGetSSOEmail(t *testing.T) {9u := &User{10Identities: []*Identity{11{12PrimaryEmail: "[email protected]",13LastSigninTime: "2022-01-01T00:00:00Z",14},15{16PrimaryEmail: "[email protected]",17LastSigninTime: "2022-03-01T00:00:00Z",18},19{20PrimaryEmail: "[email protected]",21LastSigninTime: "2022-02-01T00:00:00Z",22},23{24PrimaryEmail: "[email protected]",25LastSigninTime: "",26},27},28}2930expectedEmail := "[email protected]"31actualEmail := u.GetSSOEmail()3233if actualEmail != expectedEmail {34t.Errorf("Expected SSO email to be %s, but got %s", expectedEmail, actualEmail)35}36}37func TestGetRandomEmail(t *testing.T) {38u := &User{39Identities: []*Identity{40{41PrimaryEmail: "",42LastSigninTime: "",43},44{45PrimaryEmail: "[email protected]",46LastSigninTime: "",47Deleted: true,48},49{50PrimaryEmail: "[email protected]",51LastSigninTime: "",52},53{54PrimaryEmail: "[email protected]",55LastSigninTime: "2022-03-01T00:00:00Z",56},57{58PrimaryEmail: "[email protected]",59LastSigninTime: "2022-02-01T00:00:00Z",60},61{62PrimaryEmail: "[email protected]",63LastSigninTime: "",64},65},66}6768expectedEmail := "[email protected]"69actualEmail := u.GetRandomEmail()7071if actualEmail != expectedEmail {72t.Errorf("Expected random email to be %s, but got %s", expectedEmail, actualEmail)73}74}757677