-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.spec.ts
40 lines (34 loc) · 1.28 KB
/
util.spec.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
import { GenerateTokenSuccessResponse } from "./authentication";
import { isTokenExpired } from "./util";
describe("util", () => {
describe("isTokenExpired", () => {
let token: GenerateTokenSuccessResponse;
beforeEach(() => {
token = {
issued_at: new Date().valueOf().toString(),
expires_in: "3600",
};
});
it("Returns true if a token is expired", () => {
const millisecondsAgo = 30 * 1000;
token = {
issued_at: new Date(Date.now() - millisecondsAgo)
.valueOf()
.toString(),
expires_in: "15",
};
expect(isTokenExpired(token)).toBe(true);
});
it("Returns false if a token is not expired", () => {
expect(isTokenExpired(token)).toBe(false);
});
it("Returns true if the remaining time on a token is less than deltaMillis", () => {
token.expires_in = "10";
expect(isTokenExpired(token, 10000)).toBe(true);
});
it("Returns false if the token still has time left, including the delta", () => {
token.expires_in = "10";
expect(isTokenExpired(token, 9000)).toBe(false);
});
});
});