-
Notifications
You must be signed in to change notification settings - Fork 990
/
Copy pathexpireUtils.spec.ts
49 lines (43 loc) · 1.39 KB
/
expireUtils.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
41
42
43
44
45
46
47
48
49
import { expect } from "chai";
import { calculateChannelExpireTTL } from "./expireUtils";
import { FirebaseError } from "../error";
describe("calculateChannelExpireTTL", () => {
const goodTests = [
{ input: "30d", want: 30 * 24 * 60 * 60 * 1000 },
{ input: "1d", want: 24 * 60 * 60 * 1000 },
{ input: "2d", want: 2 * 24 * 60 * 60 * 1000 },
{ input: "2h", want: 2 * 60 * 60 * 1000 },
{ input: "56m", want: 56 * 60 * 1000 },
] as const;
for (const test of goodTests) {
it(`should be able to parse time ${test.input}`, () => {
const got = calculateChannelExpireTTL(test.input);
expect(got).to.equal(test.want, `unexpected output for ${test.input}`);
});
}
const badTests = [
{ input: "1.5d" },
{ input: "2x" },
{ input: "2dd" },
{ input: "0.5m" },
{ input: undefined },
];
for (const test of badTests) {
it(`should be able to parse time ${test.input || "undefined"}`, () => {
expect(() => calculateChannelExpireTTL(test.input as any)).to.throw(
FirebaseError,
/flag must be a duration string/,
);
});
}
it("should throw if greater than 30d", () => {
expect(() => calculateChannelExpireTTL("31d")).to.throw(
FirebaseError,
/not be longer than 30d/,
);
expect(() => calculateChannelExpireTTL(`${31 * 24}h`)).to.throw(
FirebaseError,
/not be longer than 30d/,
);
});
});