-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83c3d1a
commit a93e35d
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
components/public-api/typescript-common/src/user-utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { Timestamp } from "@bufbuild/protobuf"; | ||
import { Identity, User, User_ProfileDetails } from "@gitpod/public-api/lib/gitpod/v1/user_pb"; | ||
import * as chai from "chai"; | ||
import { getPrimaryEmail } from "./user-utils"; | ||
|
||
const expect = chai.expect; | ||
|
||
describe("getPrimaryEmail", function () { | ||
const user = new User({ | ||
organizationId: undefined, | ||
profile: new User_ProfileDetails({ | ||
emailAddress: "[email protected]", | ||
}), | ||
identities: [ | ||
new Identity({ | ||
primaryEmail: "[email protected]", | ||
}), | ||
], | ||
}); | ||
it(`should return email from profile exists`, () => { | ||
const email = getPrimaryEmail(user); | ||
expect(email).to.equal(user.profile!.emailAddress); | ||
}); | ||
it(`should return email from SSO provider for org-owned accounts`, () => { | ||
const ssoEmail = "[email protected]"; | ||
user.identities.unshift( | ||
new Identity({ | ||
primaryEmail: ssoEmail, | ||
// SSO identities have `lastSigninTime` set | ||
lastSigninTime: Timestamp.fromDate(new Date()), | ||
}), | ||
); | ||
user.organizationId = "any"; | ||
const email = getPrimaryEmail(user); | ||
expect(email).to.equal(ssoEmail); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters