-
Notifications
You must be signed in to change notification settings - Fork 376
/
Copy pathisTokenValid.test.js
55 lines (48 loc) · 1.17 KB
/
isTokenValid.test.js
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
49
50
51
52
53
54
55
import { isTokenValid } from "./fast.js";
import { datetime } from "@xmpp/time";
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
it("returns false if the token.mechanism is not available", async () => {
expect(
isTokenValid(
{
expiry: datetime(tomorrow),
mechanism: "bar",
},
["foo"],
),
).toBe(false);
});
it("returns true if the token.mechanism is available", async () => {
expect(
isTokenValid({ expiry: datetime(tomorrow), mechanism: "foo" }, ["foo"]),
).toBe(true);
});
it("returns false if the token is expired", async () => {
expect(
isTokenValid(
{
expiry: datetime(yesterday),
mechanism: "foo",
},
["foo"],
),
).toBe(false);
});
it("returns true if the token is not expired", async () => {
expect(
isTokenValid(
{
expiry: datetime(tomorrow),
mechanism: "foo",
},
["foo"],
),
).toBe(true);
});
it("returns false if the token is nullish", async () => {
expect(isTokenValid(null)).toBe(false);
expect(isTokenValid(undefined)).toBe(false);
});