forked from authts/oidc-client-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.test.ts
48 lines (35 loc) · 1.17 KB
/
User.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { User } from "./User";
import { Timer } from "./utils";
describe("User", () => {
let now: number;
beforeEach(() => {
now = 0;
jest.spyOn(Timer, "getEpochTime").mockImplementation(() => now);
});
afterEach(() => {
jest.restoreAllMocks();
});
describe("expired", () => {
it("should calculate how much time left", () => {
const subject = new User({ expires_at: 100 } as never);
expect(subject.expired).toEqual(false);
// act
now += 100;
// assert
expect(subject.expired).toEqual(true);
});
});
describe("scopes", () => {
it("should return list of scopes", () => {
let subject = new User({ scope: "foo" } as never);
// assert
expect(subject.scopes).toEqual(["foo"]);
subject = new User({ scope: "foo bar" } as never);
// assert
expect(subject.scopes).toEqual(["foo", "bar"]);
subject = new User({ scope: "foo bar baz" } as never);
// assert
expect(subject.scopes).toEqual(["foo", "bar", "baz"]);
});
});
});