-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
46 lines (41 loc) · 989 Bytes
/
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
import {
assert,
assertEquals,
assertThrows,
} from "https://deno.land/std@0.95.0/testing/asserts.ts";
import { decodeString, getDate, InvalidObjectId, objectId } from "./mod.ts";
Deno.test("Generate objectId", () => {
const id = objectId();
assertEquals(id.length, 12);
});
Deno.test("decodeString", () => {
const id = decodeString("60950fa4beaf70cffc9ac75d");
assert(id instanceof Uint8Array);
assertEquals(id.length, 12);
});
Deno.test("decodeString error", () => {
assertThrows(() => decodeString("60950fa4beaf70cffc9ac7"), InvalidObjectId);
});
Deno.test("getDate", () => {
const id = new Uint8Array([
0x60,
0x95,
0x0f,
0xa4,
0xbe,
0xaf,
0x70,
0xcf,
0xfc,
0x9a,
0xc7,
0x5d,
]);
const date = getDate(id);
assertEquals(date.getTime(), 1620381604000);
});
Deno.test("Integration", () => {
const id = objectId();
const date = getDate(id);
assertEquals(date.getTime() / 1000, ~~(Date.now() / 1000));
});