-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.test.ts
79 lines (69 loc) · 1.85 KB
/
store.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { assertEquals, assertIsError } from "https://deno.land/[email protected]/testing/asserts.ts"
import init, { TodoStore } from "./xotodo-store/pkg/xotodo_store.js"
async function setup() {
await init(Deno.readFile("xotodo-store/pkg/xotodo_store_bg.wasm"))
}
const item = {
title: "testibus",
lineNumber: 12,
tsIndexed: new Date().getTime(),
status: "closed",
dueDate: new Date().getTime()
}
await setup()
Deno.test({
name: "storing a todo",
fn: () => {
const store = new TodoStore()
store.set_item("/my/test/path", [item])
const todos = store.get_items()
assertEquals(Object.keys(todos).length, 1)
assertEquals(todos["/my/test/path"][0].lineNumber, 12)
},
})
Deno.test({
name: "cannot pass Date object",
fn: () => {
const store = new TodoStore()
try {
store.set_item("/my/test/path", [{
title: "testibus",
lineNumber: 12,
tsIndexed: new Date(), // currently, cannot pass Date object
status: "closed",
dueDate: new Date().getTime()
}])
} catch (error) {
assertIsError(error)
}
assertEquals(Object.keys(store.get_items()).length, 0)
},
})
Deno.test({
name: "remove item",
fn: () => {
const store = new TodoStore()
store.set_item("/my/test/path", [item])
store.remove_item("/my/test/path")
const todos = store.get_items()
assertEquals(Object.keys(todos).length, 0)
},
})
Deno.test({
name: "cannot get non-existing item ",
fn: () => {
const store = new TodoStore()
const todos = store.get_item("/my/test/path")
assertEquals(todos, null)
assertEquals(Object.keys(store.get_items()).length, 0)
},
})
Deno.test({
name: "get item",
fn: () => {
const store = new TodoStore()
store.set_item("/my/test/path", [item])
const todos = store.get_item("/my/test/path")
assertEquals(todos[0].lineNumber, 12)
},
})