-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdb.test.ts
More file actions
127 lines (100 loc) · 3.1 KB
/
db.test.ts
File metadata and controls
127 lines (100 loc) · 3.1 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { PerspectivismDb } from './db'
import Memory from 'lowdb/adapters/Memory'
import { v4 as uuidv4 } from 'uuid'
describe('PerspectivismDb', () => {
let db
let pUUID
beforeEach(() => {
db = new PerspectivismDb(new Memory())
pUUID = uuidv4()
})
it('can store and retrieve objects by name', () => {
const obj = { test: 'object' }
const name = 'linkName'
db.storeLink(pUUID, obj, name)
const result = db.getLink(pUUID, name)
expect(result).toEqual(obj)
})
it('can call getLink() multiple times', () => {
const obj = { test: 'object' }
const name = 'linkName'
db.storeLink(pUUID, obj, name)
for(let i=0; i<3; i++) {
expect(db.getLink(pUUID, name)).toEqual(obj)
}
})
it('can getAllLinks', () => {
const obj1 = { test: 'object1' }
const name1 = 'linkName1'
db.storeLink(pUUID, obj1, name1)
const obj2 = { test: 'object2' }
const name2 = 'linkName2'
db.storeLink(pUUID, obj2, name2)
const allLinks = db.getAllLinks(pUUID)
expect(allLinks).toEqual([
{
link: obj1,
name: name1,
},
{
link: obj2,
name: name2,
}
])
})
it('can getAllLinks with only one link (attached)', () => {
const obj1 = { test: 'object1' }
const name1 = 'linkName1'
db.storeLink(pUUID, obj1, name1)
db.attachSource(pUUID, 'root', name1)
db.attachTarget(pUUID, 'link-url', name1)
const allLinks = db.getAllLinks(pUUID)
expect(allLinks).toEqual([
{
link: obj1,
name: name1,
}
])
})
it('can call getAllLinks() multiple times', () => {
const obj1 = { test: 'object1' }
const name1 = 'linkName1'
db.storeLink(pUUID, obj1, name1)
for(let i=0; i<3; i++) {
expect(db.getAllLinks(pUUID)).toEqual([
{
link: obj1,
name: name1,
}
])
}
})
it('can getLinksBySource', () => {
const obj1 = { test: 'object1' }
const name1 = 'linkName1'
db.storeLink(pUUID, obj1, name1)
const obj2 = { test: 'object2' }
const name2 = 'linkName2'
db.storeLink(pUUID, obj2, name2)
db.attachSource(pUUID, name1, name2)
const result = db.getLinksBySource(pUUID, name1)
expect(result).toEqual([{
link: obj2,
name: name2
}])
})
it('can getLinksByTarget', () => {
const obj1 = { test: 'object1' }
const name1 = 'linkName1'
db.storeLink(pUUID, obj1, name1)
const obj2 = { test: 'object2' }
const name2 = 'linkName2'
db.storeLink(pUUID, obj2, name2)
db.attachTarget(pUUID, name1, name2)
const result = db.getLinksByTarget(pUUID, name1)
expect(result).toEqual([{
link: obj2,
name: name2
}])
})
})