coh-content-db 2.0.0-rc.7 → 2.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +1 -1
- package/.github/workflows/pull-request.yml +1 -1
- package/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +38 -0
- package/README.md +24 -7
- package/dist/coh-content-db.d.ts +108 -64
- package/dist/coh-content-db.js +232 -210
- package/dist/coh-content-db.js.map +1 -1
- package/dist/coh-content-db.mjs +232 -209
- package/dist/coh-content-db.mjs.map +1 -1
- package/package.json +1 -1
- package/src/main/api/{content-bundle.ts → bundle-data.ts} +5 -27
- package/src/main/api/bundle-header-data.ts +37 -0
- package/src/main/db/abstract-index.ts +41 -0
- package/src/main/db/badge-index.ts +7 -18
- package/src/main/db/bundle-header.ts +44 -0
- package/src/main/db/coh-content-database.ts +81 -72
- package/src/main/index.ts +3 -4
- package/src/test/api/bundle-data.fixture.ts +6 -0
- package/src/test/api/bundle-header-data.fixture.ts +6 -0
- package/src/test/db/abstract-index.test.ts +86 -0
- package/src/test/db/badge-index.test.ts +149 -122
- package/src/test/db/bundle-header.test.ts +76 -0
- package/src/test/db/coh-content-database.test.ts +164 -79
- package/src/test/integration.test.ts +16 -0
- package/src/main/api/change.ts +0 -17
- package/src/main/changelog.ts +0 -29
- package/src/main/db/bundle-metadata.ts +0 -39
- package/src/test/api/content-bundle.fixture.ts +0 -6
- package/src/test/api/content-bundle.test.ts +0 -14
- package/src/test/changelog.test.ts +0 -36
- package/src/test/db/bundle-metadata.test.ts +0 -67
- package/src/test/index.test.ts +0 -14
|
@@ -5,39 +5,43 @@ import { badgeRequirementDataFixture } from '../api/badge-requirement-data.fixtu
|
|
|
5
5
|
describe(BadgeIndex.name, () => {
|
|
6
6
|
describe('Constructor', () => {
|
|
7
7
|
test(`should throw an error on duplicate key`, () => {
|
|
8
|
-
const
|
|
8
|
+
const index = new BadgeIndex()
|
|
9
|
+
expect(() => index.load([
|
|
9
10
|
new Badge(badgeDataFixture.create({ key: 'foo' })),
|
|
10
11
|
new Badge(badgeDataFixture.create({ key: 'foo' })),
|
|
11
|
-
]
|
|
12
|
-
expect(() => new BadgeIndex(data)).toThrow('Duplicate badge key [foo]')
|
|
12
|
+
])).toThrow('Duplicate key [foo]')
|
|
13
13
|
})
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('get', () => {
|
|
17
17
|
test(`should retrieve badge from the index`, () => {
|
|
18
18
|
const data = [new Badge(badgeDataFixture.create({ key: 'foo' }))]
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const index = new BadgeIndex()
|
|
21
|
+
index.load(data)
|
|
22
|
+
expect(index.get('foo')).not.toBeUndefined()
|
|
21
23
|
})
|
|
22
24
|
|
|
23
25
|
test(`should return undefined for unknown badge`, () => {
|
|
24
|
-
expect(new BadgeIndex(
|
|
26
|
+
expect(new BadgeIndex().get('foo')).toBeUndefined()
|
|
25
27
|
})
|
|
26
28
|
|
|
27
29
|
test(`should return undefined for undefined key`, () => {
|
|
28
|
-
|
|
30
|
+
const key = undefined
|
|
31
|
+
expect(new BadgeIndex().get(key)).toBeUndefined()
|
|
29
32
|
})
|
|
30
33
|
})
|
|
31
34
|
|
|
32
|
-
describe('
|
|
35
|
+
describe('search', () => {
|
|
33
36
|
test(`should return everything for an empty query`, () => {
|
|
34
|
-
const
|
|
37
|
+
const index = new BadgeIndex()
|
|
38
|
+
index.load([
|
|
35
39
|
new Badge(badgeDataFixture.create({ key: 'foo-1', acquisition: 'Foo 1' })),
|
|
36
40
|
new Badge(badgeDataFixture.create({ key: 'foo-2', acquisition: 'Foo 2' })),
|
|
37
41
|
new Badge(badgeDataFixture.create({ key: 'bar-1', acquisition: 'Bar 1' })),
|
|
38
|
-
]
|
|
42
|
+
])
|
|
39
43
|
|
|
40
|
-
const result =
|
|
44
|
+
const result = index.search()
|
|
41
45
|
const keys = result.items.map(x => x.key)
|
|
42
46
|
expect(keys).toStrictEqual(['foo-1', 'foo-2', 'bar-1'])
|
|
43
47
|
expect(keys).toContain('foo-1')
|
|
@@ -47,80 +51,86 @@ describe(BadgeIndex.name, () => {
|
|
|
47
51
|
|
|
48
52
|
describe('query', () => {
|
|
49
53
|
test(`should match on badge name`, () => {
|
|
50
|
-
const
|
|
54
|
+
const index = new BadgeIndex()
|
|
55
|
+
index.load([
|
|
51
56
|
new Badge(badgeDataFixture.create({ key: 'match-1', name: [{ value: 'Foo 1' }] })),
|
|
52
57
|
new Badge(badgeDataFixture.create({ key: 'match-2', name: [{ value: 'Foo 2' }, { value: 'Bar 2' }] })),
|
|
53
58
|
new Badge(badgeDataFixture.create({ key: 'match-3', name: [{ value: 'Bar 3' }, { value: 'Foo 3' }] })),
|
|
54
59
|
new Badge(badgeDataFixture.create({ key: 'miss-1', name: [{ value: 'Bar 4' }] })),
|
|
55
|
-
]
|
|
60
|
+
])
|
|
56
61
|
|
|
57
|
-
const result =
|
|
62
|
+
const result = index.search({ query: { str: 'Foo', on: { name: true } } })
|
|
58
63
|
const keys = result.items.map(x => x.key)
|
|
59
64
|
expect(keys).toStrictEqual(['match-1', 'match-2', 'match-3'])
|
|
60
65
|
})
|
|
61
66
|
|
|
62
67
|
test(`should match on badge text`, () => {
|
|
63
|
-
const
|
|
68
|
+
const index = new BadgeIndex()
|
|
69
|
+
index.load([
|
|
64
70
|
new Badge(badgeDataFixture.create({ key: 'match-1', badgeText: [{ value: 'Foo 1' }] })),
|
|
65
71
|
new Badge(badgeDataFixture.create({ key: 'match-2', badgeText: [{ value: 'Foo 2' }, { value: 'Bar 2' }] })),
|
|
66
72
|
new Badge(badgeDataFixture.create({ key: 'match-3', badgeText: [{ value: 'Bar 3' }, { value: 'Foo 3' }] })),
|
|
67
73
|
new Badge(badgeDataFixture.create({ key: 'miss-1', badgeText: [{ value: 'Bar 4' }] })),
|
|
68
74
|
new Badge(badgeDataFixture.create({ key: 'miss-2', badgeText: undefined })),
|
|
69
|
-
]
|
|
75
|
+
])
|
|
70
76
|
|
|
71
|
-
const result =
|
|
77
|
+
const result = index.search({ query: { str: 'Foo', on: { badgeText: true } } })
|
|
72
78
|
const keys = result.items.map(x => x.key)
|
|
73
79
|
expect(keys).toStrictEqual(['match-1', 'match-2', 'match-3'])
|
|
74
80
|
})
|
|
75
81
|
|
|
76
82
|
test(`should match on acquisition`, () => {
|
|
77
|
-
const
|
|
83
|
+
const index = new BadgeIndex()
|
|
84
|
+
index.load([
|
|
78
85
|
new Badge(badgeDataFixture.create({ key: 'match-1', acquisition: 'Foo 1' })),
|
|
79
86
|
new Badge(badgeDataFixture.create({ key: 'match-2', acquisition: 'Foo 2' })),
|
|
80
87
|
new Badge(badgeDataFixture.create({ key: 'miss-1', acquisition: 'Bar 1' })),
|
|
81
88
|
new Badge(badgeDataFixture.create({ key: 'miss-2', acquisition: undefined })),
|
|
82
|
-
]
|
|
89
|
+
])
|
|
83
90
|
|
|
84
|
-
const result =
|
|
91
|
+
const result = index.search({ query: { str: 'Foo', on: { acquisition: true } } })
|
|
85
92
|
const keys = result.items.map(x => x.key)
|
|
86
93
|
expect(keys).toStrictEqual(['match-1', 'match-2'])
|
|
87
94
|
})
|
|
88
95
|
|
|
89
96
|
test(`should match on effect`, () => {
|
|
90
|
-
const
|
|
97
|
+
const index = new BadgeIndex()
|
|
98
|
+
index.load([
|
|
91
99
|
new Badge(badgeDataFixture.create({ key: 'match-1', effect: 'Foo 1' })),
|
|
92
100
|
new Badge(badgeDataFixture.create({ key: 'match-2', effect: 'Foo 2' })),
|
|
93
101
|
new Badge(badgeDataFixture.create({ key: 'miss-1', effect: 'Bar 1' })),
|
|
94
102
|
new Badge(badgeDataFixture.create({ key: 'miss-2', effect: undefined })),
|
|
95
|
-
]
|
|
103
|
+
])
|
|
96
104
|
|
|
97
|
-
const result =
|
|
105
|
+
const result = index.search({ query: { str: 'Foo', on: { effect: true } } })
|
|
98
106
|
const keys = result.items.map(x => x.key)
|
|
99
107
|
expect(keys).toStrictEqual(['match-1', 'match-2'])
|
|
100
108
|
})
|
|
101
109
|
|
|
102
110
|
test(`should match on notes`, () => {
|
|
103
|
-
const
|
|
111
|
+
const index = new BadgeIndex()
|
|
112
|
+
index.load([
|
|
104
113
|
new Badge(badgeDataFixture.create({ key: 'match-1', notes: 'Foo 1' })),
|
|
105
114
|
new Badge(badgeDataFixture.create({ key: 'match-2', notes: 'Foo 2' })),
|
|
106
115
|
new Badge(badgeDataFixture.create({ key: 'miss-1', notes: 'Bar 1' })),
|
|
107
116
|
new Badge(badgeDataFixture.create({ key: 'miss-2', notes: undefined })),
|
|
108
|
-
]
|
|
117
|
+
])
|
|
109
118
|
|
|
110
|
-
const result =
|
|
119
|
+
const result = index.search({ query: { str: 'Foo', on: { notes: true } } })
|
|
111
120
|
const keys = result.items.map(x => x.key)
|
|
112
121
|
expect(keys).toStrictEqual(['match-1', 'match-2'])
|
|
113
122
|
})
|
|
114
123
|
|
|
115
124
|
test(`should match on setTitle`, () => {
|
|
116
|
-
const
|
|
125
|
+
const index = new BadgeIndex()
|
|
126
|
+
index.load([
|
|
117
127
|
new Badge(badgeDataFixture.create({ key: 'match-1', setTitleId: [123] })),
|
|
118
128
|
new Badge(badgeDataFixture.create({ key: 'match-2', setTitleId: [456, 123] })),
|
|
119
129
|
new Badge(badgeDataFixture.create({ key: 'miss-1', setTitleId: [456] })),
|
|
120
130
|
new Badge(badgeDataFixture.create({ key: 'miss-2', setTitleId: undefined })),
|
|
121
|
-
]
|
|
131
|
+
])
|
|
122
132
|
|
|
123
|
-
const result =
|
|
133
|
+
const result = index.search({ query: { str: '123', on: { setTitle: true } } })
|
|
124
134
|
|
|
125
135
|
expect(result.items).toHaveLength(2)
|
|
126
136
|
const keys = result.items.map(x => x.key)
|
|
@@ -128,37 +138,40 @@ describe(BadgeIndex.name, () => {
|
|
|
128
138
|
})
|
|
129
139
|
|
|
130
140
|
test(`should match the start of a string`, () => {
|
|
131
|
-
const
|
|
141
|
+
const index = new BadgeIndex()
|
|
142
|
+
index.load([
|
|
132
143
|
new Badge(badgeDataFixture.create({ key: 'match-1', acquisition: 'Foo 1' })),
|
|
133
144
|
new Badge(badgeDataFixture.create({ key: 'match-2', acquisition: 'Foo 2' })),
|
|
134
145
|
new Badge(badgeDataFixture.create({ key: 'miss-1', acquisition: 'Bar 1' })),
|
|
135
|
-
]
|
|
146
|
+
])
|
|
136
147
|
|
|
137
|
-
const result =
|
|
148
|
+
const result = index.search({ query: { str: 'Fo', on: { acquisition: true } } })
|
|
138
149
|
const keys = result.items.map(x => x.key)
|
|
139
150
|
expect(keys).toStrictEqual(['match-1', 'match-2'])
|
|
140
151
|
})
|
|
141
152
|
|
|
142
153
|
test(`should be case insensitive`, () => {
|
|
143
|
-
const
|
|
154
|
+
const index = new BadgeIndex()
|
|
155
|
+
index.load([
|
|
144
156
|
new Badge(badgeDataFixture.create({ key: 'match-1', acquisition: 'Foo 1' })),
|
|
145
157
|
new Badge(badgeDataFixture.create({ key: 'match-2', acquisition: 'Foo 2' })),
|
|
146
158
|
new Badge(badgeDataFixture.create({ key: 'miss-1', acquisition: 'Bar 1' })),
|
|
147
|
-
]
|
|
159
|
+
])
|
|
148
160
|
|
|
149
|
-
const result =
|
|
161
|
+
const result = index.search({ query: { str: 'foo', on: { acquisition: true } } })
|
|
150
162
|
const keys = result.items.map(x => x.key)
|
|
151
163
|
expect(keys).toStrictEqual(['match-1', 'match-2'])
|
|
152
164
|
})
|
|
153
165
|
|
|
154
166
|
test(`should default to querying on name only`, () => {
|
|
155
|
-
const
|
|
167
|
+
const index = new BadgeIndex()
|
|
168
|
+
index.load([
|
|
156
169
|
new Badge(badgeDataFixture.create({ key: 'match-1', name: [{ value: 'Foo 1' }] })),
|
|
157
170
|
new Badge(badgeDataFixture.create({ key: 'miss-1', acquisition: 'Foo 2' })),
|
|
158
171
|
new Badge(badgeDataFixture.create({ key: 'miss-2', name: [{ value: 'Bar 1' }] })),
|
|
159
|
-
]
|
|
172
|
+
])
|
|
160
173
|
|
|
161
|
-
const result =
|
|
174
|
+
const result = index.search({ query: { str: 'foo' } })
|
|
162
175
|
|
|
163
176
|
const keys = result.items.map(x => x.key)
|
|
164
177
|
expect(keys).toStrictEqual(['match-1'])
|
|
@@ -167,37 +180,40 @@ describe(BadgeIndex.name, () => {
|
|
|
167
180
|
|
|
168
181
|
describe('filter', () => {
|
|
169
182
|
test(`should filter nothing if not specified`, () => {
|
|
170
|
-
const
|
|
183
|
+
const index = new BadgeIndex()
|
|
184
|
+
index.load([
|
|
171
185
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
172
186
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
173
187
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
174
188
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
175
189
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
176
190
|
new Badge(badgeDataFixture.create({ key: 'badge-6' })),
|
|
177
|
-
]
|
|
191
|
+
])
|
|
178
192
|
|
|
179
|
-
const result =
|
|
193
|
+
const result = index.search()
|
|
180
194
|
const keys = result.items.map(x => x.key)
|
|
181
195
|
expect(keys).toStrictEqual(['badge-1', 'badge-2', 'badge-3', 'badge-4', 'badge-5', 'badge-6'])
|
|
182
196
|
})
|
|
183
197
|
|
|
184
198
|
test(`should filter on badge type`, () => {
|
|
185
|
-
const
|
|
199
|
+
const index = new BadgeIndex()
|
|
200
|
+
index.load([
|
|
186
201
|
new Badge(badgeDataFixture.create({ key: 'badge-1', type: 'exploration' })),
|
|
187
202
|
new Badge(badgeDataFixture.create({ key: 'badge-2', type: 'exploration' })),
|
|
188
203
|
new Badge(badgeDataFixture.create({ key: 'badge-3', type: 'history' })),
|
|
189
204
|
new Badge(badgeDataFixture.create({ key: 'badge-4', type: 'history' })),
|
|
190
205
|
new Badge(badgeDataFixture.create({ key: 'badge-5', type: 'accolade' })),
|
|
191
206
|
new Badge(badgeDataFixture.create({ key: 'badge-6', type: 'accolade' })),
|
|
192
|
-
]
|
|
207
|
+
])
|
|
193
208
|
|
|
194
|
-
const result =
|
|
209
|
+
const result = index.search({ filter: { type: 'history' } })
|
|
195
210
|
const keys = result.items.map(x => x.key)
|
|
196
211
|
expect(keys).toStrictEqual(['badge-3', 'badge-4'])
|
|
197
212
|
})
|
|
198
213
|
|
|
199
214
|
test(`should filter on badge zone`, () => {
|
|
200
|
-
const
|
|
215
|
+
const index = new BadgeIndex()
|
|
216
|
+
index.load([
|
|
201
217
|
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
202
218
|
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
203
219
|
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
@@ -209,24 +225,25 @@ describe(BadgeIndex.name, () => {
|
|
|
209
225
|
],
|
|
210
226
|
})),
|
|
211
227
|
new Badge(badgeDataFixture.create({ key: 'badge-6', requirements: [{ location: undefined }] })),
|
|
212
|
-
]
|
|
228
|
+
])
|
|
213
229
|
|
|
214
|
-
const result =
|
|
230
|
+
const result = index.search({ filter: { zoneKey: 'perez-park' } })
|
|
215
231
|
const keys = result.items.map(x => x.key)
|
|
216
232
|
expect(keys).toStrictEqual(['badge-2'])
|
|
217
233
|
})
|
|
218
234
|
|
|
219
235
|
test(`should filter on alignment`, () => {
|
|
220
|
-
const
|
|
236
|
+
const index = new BadgeIndex()
|
|
237
|
+
index.load([
|
|
221
238
|
new Badge(badgeDataFixture.create({ key: 'badge-1', morality: ['hero'] })),
|
|
222
239
|
new Badge(badgeDataFixture.create({ key: 'badge-2', morality: ['villain'] })),
|
|
223
240
|
new Badge(badgeDataFixture.create({ key: 'badge-3', morality: ['loyalist'] })),
|
|
224
241
|
new Badge(badgeDataFixture.create({ key: 'badge-4', morality: ['hero', 'villain'] })),
|
|
225
242
|
new Badge(badgeDataFixture.create({ key: 'badge-5', morality: ['villain', 'loyalist'] })),
|
|
226
243
|
new Badge(badgeDataFixture.create({ key: 'badge-6', morality: ['hero', 'villain', 'loyalist'] })),
|
|
227
|
-
]
|
|
244
|
+
])
|
|
228
245
|
|
|
229
|
-
const result =
|
|
246
|
+
const result = index.search({ filter: { morality: 'hero' } })
|
|
230
247
|
const keys = result.items.map(x => x.key)
|
|
231
248
|
expect(keys).toStrictEqual(['badge-1', 'badge-4', 'badge-6'])
|
|
232
249
|
})
|
|
@@ -234,280 +251,291 @@ describe(BadgeIndex.name, () => {
|
|
|
234
251
|
|
|
235
252
|
describe('pagination', () => {
|
|
236
253
|
test(`should return all results with no pagination data`, () => {
|
|
237
|
-
const
|
|
254
|
+
const index = new BadgeIndex()
|
|
255
|
+
index.load([
|
|
238
256
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
239
257
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
240
258
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
241
259
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
242
260
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
243
261
|
new Badge(badgeDataFixture.create({ key: 'badge-6' })),
|
|
244
|
-
]
|
|
262
|
+
])
|
|
245
263
|
|
|
246
|
-
const result =
|
|
264
|
+
const result = index.search()
|
|
247
265
|
const keys = result.items.map(x => x.key)
|
|
248
266
|
expect(keys).toStrictEqual(['badge-1', 'badge-2', 'badge-3', 'badge-4', 'badge-5', 'badge-6'])
|
|
249
267
|
})
|
|
250
268
|
|
|
251
269
|
test(`should be 1-based for page number`, () => {
|
|
252
|
-
const result = new BadgeIndex(
|
|
270
|
+
const result = new BadgeIndex().search()
|
|
253
271
|
expect(result.page).toBe(1)
|
|
254
272
|
})
|
|
255
273
|
|
|
256
274
|
test(`should return the requested page size`, () => {
|
|
257
|
-
const
|
|
275
|
+
const index = new BadgeIndex()
|
|
276
|
+
index.load([
|
|
258
277
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
259
278
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
260
279
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
261
280
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
262
281
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
263
282
|
new Badge(badgeDataFixture.create({ key: 'badge-6' })),
|
|
264
|
-
]
|
|
283
|
+
])
|
|
265
284
|
|
|
266
|
-
const result =
|
|
285
|
+
const result = index.search({ pageSize: 2 })
|
|
267
286
|
expect(result.items).toHaveLength(2)
|
|
268
287
|
})
|
|
269
288
|
|
|
270
289
|
test(`should return the start of the array with no page specified`, () => {
|
|
271
|
-
const
|
|
290
|
+
const index = new BadgeIndex()
|
|
291
|
+
index.load([
|
|
272
292
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
273
293
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
274
294
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
275
295
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
276
296
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
277
297
|
new Badge(badgeDataFixture.create({ key: 'badge-6' })),
|
|
278
|
-
]
|
|
298
|
+
])
|
|
279
299
|
|
|
280
|
-
const result =
|
|
300
|
+
const result = index.search({ pageSize: 2 })
|
|
281
301
|
const keys = result.items.map(x => x.key)
|
|
282
302
|
expect(keys).toStrictEqual(['badge-1', 'badge-2'])
|
|
283
303
|
})
|
|
284
304
|
|
|
285
305
|
test(`should return results from the middle of the array with a page specified`, () => {
|
|
286
|
-
const
|
|
306
|
+
const index = new BadgeIndex()
|
|
307
|
+
index.load([
|
|
287
308
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
288
309
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
289
310
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
290
311
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
291
312
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
292
313
|
new Badge(badgeDataFixture.create({ key: 'badge-6' })),
|
|
293
|
-
]
|
|
314
|
+
])
|
|
294
315
|
|
|
295
|
-
const result =
|
|
316
|
+
const result = index.search({ page: 2, pageSize: 2 })
|
|
296
317
|
const keys = result.items.map(x => x.key)
|
|
297
318
|
expect(keys).toStrictEqual(['badge-3', 'badge-4'])
|
|
298
319
|
})
|
|
299
320
|
|
|
300
321
|
test(`should return a partial page if at the end of the array`, () => {
|
|
301
|
-
const
|
|
322
|
+
const index = new BadgeIndex()
|
|
323
|
+
index.load([
|
|
302
324
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
303
325
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
304
326
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
305
327
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
306
328
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
307
|
-
]
|
|
329
|
+
])
|
|
308
330
|
|
|
309
|
-
const result =
|
|
331
|
+
const result = index.search({ page: 3, pageSize: 2 })
|
|
310
332
|
const keys = result.items.map(x => x.key)
|
|
311
333
|
expect(keys).toStrictEqual(['badge-5'])
|
|
312
334
|
})
|
|
313
335
|
|
|
314
336
|
test(`should return the correct total entry count`, () => {
|
|
315
|
-
const
|
|
337
|
+
const index = new BadgeIndex()
|
|
338
|
+
index.load([
|
|
316
339
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
317
340
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
318
341
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
319
342
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
320
343
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
321
|
-
]
|
|
344
|
+
])
|
|
322
345
|
|
|
323
|
-
const result =
|
|
346
|
+
const result = index.search({ page: 1, pageSize: 2 })
|
|
324
347
|
expect(result.totalItems).toBe(5)
|
|
325
348
|
})
|
|
326
349
|
|
|
327
350
|
test(`should return the page size`, () => {
|
|
328
|
-
const
|
|
351
|
+
const index = new BadgeIndex()
|
|
352
|
+
index.load([
|
|
329
353
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
330
354
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
331
355
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
332
356
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
333
357
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
334
|
-
]
|
|
358
|
+
])
|
|
335
359
|
|
|
336
|
-
const result =
|
|
360
|
+
const result = index.search({ pageSize: 2 })
|
|
337
361
|
expect(result.pageSize).toBe(2)
|
|
338
362
|
})
|
|
339
363
|
|
|
340
364
|
test(`should return the correct total page count`, () => {
|
|
341
|
-
const
|
|
365
|
+
const index = new BadgeIndex()
|
|
366
|
+
index.load([
|
|
342
367
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
343
368
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
344
369
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
345
370
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
346
371
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
347
|
-
]
|
|
372
|
+
])
|
|
348
373
|
|
|
349
|
-
const result =
|
|
374
|
+
const result = index.search({ pageSize: 2 })
|
|
350
375
|
expect(result.totalPages).toBe(3)
|
|
351
376
|
})
|
|
352
377
|
|
|
353
378
|
test(`should return a total page count of 1 when no page size is provided`, () => {
|
|
354
|
-
const
|
|
379
|
+
const index = new BadgeIndex()
|
|
380
|
+
index.load([
|
|
355
381
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
356
382
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
357
383
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
358
384
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
359
385
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
360
|
-
]
|
|
386
|
+
])
|
|
361
387
|
|
|
362
|
-
const result =
|
|
388
|
+
const result = index.search()
|
|
363
389
|
expect(result.totalPages).toBe(1)
|
|
364
390
|
})
|
|
365
391
|
|
|
366
392
|
test(`should return the last page if a page is requested past the max`, () => {
|
|
367
|
-
const
|
|
393
|
+
const index = new BadgeIndex()
|
|
394
|
+
index.load([
|
|
368
395
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
369
396
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
370
397
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
371
398
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
372
399
|
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
373
|
-
]
|
|
400
|
+
])
|
|
374
401
|
|
|
375
|
-
const result =
|
|
402
|
+
const result = index.search({ pageSize: 2, page: 10 })
|
|
376
403
|
const keys = result.items.map(x => x.key)
|
|
377
404
|
expect(keys).toStrictEqual(['badge-5'])
|
|
378
405
|
expect(result.page).toBe(3)
|
|
379
406
|
})
|
|
380
407
|
|
|
381
408
|
test(`should return the first page if a page is requested lower than 1`, () => {
|
|
382
|
-
const result = new BadgeIndex(
|
|
409
|
+
const result = new BadgeIndex().search({ page: -10 })
|
|
383
410
|
expect(result.page).toBe(1)
|
|
384
411
|
})
|
|
385
412
|
})
|
|
386
413
|
|
|
387
414
|
describe('sort', () => {
|
|
388
415
|
test(`should not modify sort if not specified`, () => {
|
|
389
|
-
const
|
|
416
|
+
const index = new BadgeIndex()
|
|
417
|
+
index.load([
|
|
390
418
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
391
419
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
392
420
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
393
421
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
394
|
-
]
|
|
395
|
-
|
|
396
|
-
const result = new BadgeIndex(data).searchBadges()
|
|
422
|
+
])
|
|
397
423
|
|
|
424
|
+
const result = index.search()
|
|
398
425
|
const keys = result.items.map(x => x.key)
|
|
399
426
|
expect(keys).toStrictEqual(['badge-1', 'badge-2', 'badge-3', 'badge-4'])
|
|
400
427
|
})
|
|
401
428
|
|
|
402
429
|
test(`should not modify sort if order is canonical`, () => {
|
|
403
|
-
const
|
|
430
|
+
const index = new BadgeIndex()
|
|
431
|
+
index.load([
|
|
404
432
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
405
433
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
406
434
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
407
435
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
408
|
-
]
|
|
409
|
-
|
|
410
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'canonical' } })
|
|
436
|
+
])
|
|
411
437
|
|
|
438
|
+
const result = index.search({ sort: { by: 'canonical' } })
|
|
412
439
|
const keys = result.items.map(x => x.key)
|
|
413
440
|
expect(keys).toStrictEqual(['badge-1', 'badge-2', 'badge-3', 'badge-4'])
|
|
414
441
|
})
|
|
415
442
|
|
|
416
443
|
test(`should reverse default sort with desc`, () => {
|
|
417
|
-
const
|
|
444
|
+
const index = new BadgeIndex()
|
|
445
|
+
index.load([
|
|
418
446
|
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
419
447
|
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
420
448
|
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
421
449
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
422
|
-
]
|
|
423
|
-
|
|
424
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { dir: 'desc' } })
|
|
450
|
+
])
|
|
425
451
|
|
|
452
|
+
const result = index.search({ sort: { dir: 'desc' } })
|
|
426
453
|
const keys = result.items.map(x => x.key)
|
|
427
454
|
expect(keys).toStrictEqual(['badge-4', 'badge-3', 'badge-2', 'badge-1'])
|
|
428
455
|
})
|
|
429
456
|
|
|
430
457
|
test(`should sort by badge name`, () => {
|
|
431
|
-
const
|
|
458
|
+
const index = new BadgeIndex()
|
|
459
|
+
index.load([
|
|
432
460
|
new Badge(badgeDataFixture.create({ key: 'badge-1', name: [{ value: 'Abc' }] })),
|
|
433
461
|
new Badge(badgeDataFixture.create({ key: 'badge-2', name: [{ value: 'XYZ' }] })),
|
|
434
462
|
new Badge(badgeDataFixture.create({ key: 'badge-3', name: [{ value: 'AAB' }] })),
|
|
435
|
-
]
|
|
436
|
-
|
|
437
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'badge-name' } })
|
|
463
|
+
])
|
|
438
464
|
|
|
465
|
+
const result = index.search({ sort: { by: 'badge-name' } })
|
|
439
466
|
const keys = result.items.map(x => x.key)
|
|
440
467
|
expect(keys).toStrictEqual(['badge-3', 'badge-1', 'badge-2'])
|
|
441
468
|
})
|
|
442
469
|
|
|
443
470
|
test(`should sort by badge name descending`, () => {
|
|
444
|
-
const
|
|
471
|
+
const index = new BadgeIndex()
|
|
472
|
+
index.load([
|
|
445
473
|
new Badge(badgeDataFixture.create({ key: 'badge-1', name: [{ value: 'Abc' }] })),
|
|
446
474
|
new Badge(badgeDataFixture.create({ key: 'badge-2', name: [{ value: 'XYZ' }] })),
|
|
447
475
|
new Badge(badgeDataFixture.create({ key: 'badge-3', name: [{ value: 'AAB' }] })),
|
|
448
|
-
]
|
|
449
|
-
|
|
450
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'badge-name', dir: 'desc' } })
|
|
476
|
+
])
|
|
451
477
|
|
|
478
|
+
const result = index.search({ sort: { by: 'badge-name', dir: 'desc' } })
|
|
452
479
|
const keys = result.items.map(x => x.key)
|
|
453
480
|
expect(keys).toStrictEqual(['badge-2', 'badge-1', 'badge-3'])
|
|
454
481
|
})
|
|
455
482
|
|
|
456
483
|
test(`should use the default badge name when sorting by name`, () => {
|
|
457
|
-
const
|
|
484
|
+
const index = new BadgeIndex()
|
|
485
|
+
index.load([
|
|
458
486
|
new Badge(badgeDataFixture.create({ key: 'badge-1', name: [{ value: 'Abc' }] })),
|
|
459
487
|
new Badge(badgeDataFixture.create({ key: 'badge-2', name: [{ value: 'XYZ' }, { sex: 'F', value: 'AAA' }] })),
|
|
460
488
|
new Badge(badgeDataFixture.create({ key: 'badge-3', name: [{ value: 'AAB' }] })),
|
|
461
|
-
]
|
|
462
|
-
|
|
463
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'badge-name' } })
|
|
489
|
+
])
|
|
464
490
|
|
|
491
|
+
const result = index.search({ sort: { by: 'badge-name' } })
|
|
465
492
|
const keys = result.items.map(x => x.key)
|
|
466
493
|
expect(keys).toStrictEqual(['badge-3', 'badge-1', 'badge-2'])
|
|
467
494
|
})
|
|
468
495
|
|
|
469
496
|
test(`should sort by zone name`, () => {
|
|
470
|
-
const
|
|
497
|
+
const index = new BadgeIndex()
|
|
498
|
+
index.load([
|
|
471
499
|
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
472
500
|
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
473
501
|
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
474
|
-
]
|
|
475
|
-
|
|
476
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key' } })
|
|
502
|
+
])
|
|
477
503
|
|
|
504
|
+
const result = index.search({ sort: { by: 'zone-key' } })
|
|
478
505
|
const keys = result.items.map(x => x.key)
|
|
479
506
|
expect(keys).toStrictEqual(['badge-3', 'badge-1', 'badge-2'])
|
|
480
507
|
})
|
|
481
508
|
|
|
482
509
|
test(`should sort by zone name descending`, () => {
|
|
483
|
-
const
|
|
510
|
+
const index = new BadgeIndex()
|
|
511
|
+
index.load([
|
|
484
512
|
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
485
513
|
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
486
514
|
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
487
|
-
]
|
|
488
|
-
|
|
489
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key', dir: 'desc' } })
|
|
515
|
+
])
|
|
490
516
|
|
|
517
|
+
const result = index.search({ sort: { by: 'zone-key', dir: 'desc' } })
|
|
491
518
|
const keys = result.items.map(x => x.key)
|
|
492
519
|
expect(keys).toStrictEqual(['badge-2', 'badge-1', 'badge-3'])
|
|
493
520
|
})
|
|
494
521
|
|
|
495
522
|
test(`should maintain canonical as secondary sort when sorting by zone name`, () => {
|
|
496
|
-
const
|
|
523
|
+
const index = new BadgeIndex()
|
|
524
|
+
index.load([
|
|
497
525
|
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
498
526
|
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
499
527
|
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
500
528
|
new Badge(badgeDataFixture.create({ key: 'badge-4', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
501
|
-
]
|
|
502
|
-
|
|
503
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key' } })
|
|
529
|
+
])
|
|
504
530
|
|
|
531
|
+
const result = index.search({ sort: { by: 'zone-key' } })
|
|
505
532
|
const keys = result.items.map(x => x.key)
|
|
506
533
|
expect(keys).toStrictEqual(['badge-4', 'badge-1', 'badge-3', 'badge-2'])
|
|
507
534
|
})
|
|
508
535
|
|
|
509
536
|
test(`should sort undefined or multiple zone names to the end`, () => {
|
|
510
|
-
const
|
|
537
|
+
const index = new BadgeIndex()
|
|
538
|
+
index.load([
|
|
511
539
|
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
512
540
|
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: undefined }] })),
|
|
513
541
|
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
@@ -518,10 +546,9 @@ describe(BadgeIndex.name, () => {
|
|
|
518
546
|
],
|
|
519
547
|
})),
|
|
520
548
|
new Badge(badgeDataFixture.create({ key: 'badge-5', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
521
|
-
]
|
|
522
|
-
|
|
523
|
-
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key' } })
|
|
549
|
+
])
|
|
524
550
|
|
|
551
|
+
const result = index.search({ sort: { by: 'zone-key' } })
|
|
525
552
|
const keys = result.items.map(x => x.key)
|
|
526
553
|
expect(keys).toStrictEqual(['badge-5', 'badge-1', 'badge-3', 'badge-2', 'badge-4'])
|
|
527
554
|
})
|