|
| 1 | +/** |
| 2 | + * Copyright (c) 2023 Gitpod GmbH. All rights reserved. |
| 3 | + * Licensed under the GNU Affero General Public License (AGPL). |
| 4 | + * See License.AGPL.txt in the project root for license information. |
| 5 | + */ |
| 6 | + |
| 7 | +import { Timestamp } from "@bufbuild/protobuf"; |
| 8 | +import { Identity, User, User_ProfileDetails } from "@gitpod/public-api/lib/gitpod/v1/user_pb"; |
| 9 | +import * as chai from "chai"; |
| 10 | +import { getPrimaryEmail } from "./user-utils"; |
| 11 | + |
| 12 | +const expect = chai.expect; |
| 13 | + |
| 14 | +describe("getPrimaryEmail", function () { |
| 15 | + const user = new User({ |
| 16 | + organizationId: undefined, |
| 17 | + profile: new User_ProfileDetails({ |
| 18 | + emailAddress: "[email protected]", |
| 19 | + }), |
| 20 | + identities: [ |
| 21 | + new Identity({ |
| 22 | + primaryEmail: "[email protected]", |
| 23 | + }), |
| 24 | + ], |
| 25 | + }); |
| 26 | + it(`should return email from profile exists`, () => { |
| 27 | + const email = getPrimaryEmail(user); |
| 28 | + expect(email).to.equal(user.profile!.emailAddress); |
| 29 | + }); |
| 30 | + it(`should return email from SSO provider for org-owned accounts`, () => { |
| 31 | + const ssoEmail = "[email protected]"; |
| 32 | + user.identities.unshift( |
| 33 | + new Identity({ |
| 34 | + primaryEmail: ssoEmail, |
| 35 | + // SSO identities have `lastSigninTime` set |
| 36 | + lastSigninTime: Timestamp.fromDate(new Date()), |
| 37 | + }), |
| 38 | + ); |
| 39 | + user.organizationId = "any"; |
| 40 | + const email = getPrimaryEmail(user); |
| 41 | + expect(email).to.equal(ssoEmail); |
| 42 | + }); |
| 43 | +}); |
0 commit comments