coh-content-db 2.0.0-rc.5 → 2.0.0-rc.7
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/README.md +7 -7
- package/dist/coh-content-db.d.ts +493 -243
- package/dist/coh-content-db.js +675 -353
- package/dist/coh-content-db.js.map +1 -1
- package/dist/coh-content-db.mjs +655 -345
- package/dist/coh-content-db.mjs.map +1 -1
- package/eslint.config.mjs +1 -0
- package/package.json +1 -1
- package/src/main/api/alignment.ts +18 -2
- package/src/main/api/badge-data.ts +15 -38
- package/src/main/api/badge-requirement-data.ts +64 -0
- package/src/main/api/badge-requirement-type.ts +32 -0
- package/src/main/api/badge-type.ts +15 -15
- package/src/main/api/contact-data.ts +48 -0
- package/src/main/api/content-bundle.ts +16 -4
- package/src/main/api/enhancement-category.ts +26 -26
- package/src/main/api/location-data.ts +28 -0
- package/src/main/api/mission-data.ts +83 -0
- package/src/main/api/mission-type.ts +2 -0
- package/src/main/api/morality.ts +31 -0
- package/src/main/api/sex.ts +8 -1
- package/src/main/api/zone-data.ts +20 -0
- package/src/main/changelog.ts +8 -3
- package/src/main/db/alignment-list.ts +54 -0
- package/src/main/db/alternates.ts +15 -32
- package/src/main/db/badge-index.ts +17 -36
- package/src/main/db/badge-requirement.ts +81 -0
- package/src/main/db/badge-search-options.ts +5 -5
- package/src/main/db/badge.ts +73 -62
- package/src/main/db/bundle-metadata.ts +3 -3
- package/src/main/db/coh-content-database.ts +60 -23
- package/src/main/db/contact.ts +62 -0
- package/src/main/db/location.ts +30 -0
- package/src/main/db/mission.ts +107 -0
- package/src/main/db/morality-list.ts +99 -0
- package/src/main/db/zone.ts +28 -0
- package/src/main/index.ts +16 -13
- package/src/main/util.ts +85 -14
- package/src/test/api/alignment.test.ts +38 -4
- package/src/test/api/badge-data.fixture.ts +1 -15
- package/src/test/api/badge-data.test.ts +3 -3
- package/src/test/api/badge-requirement-data.fixture.ts +7 -0
- package/src/test/api/badge-requirement-type.test.ts +31 -0
- package/src/test/api/badge-type.test.ts +5 -5
- package/src/test/api/contact-data.fixture.ts +7 -0
- package/src/test/api/content-bundle.fixture.ts +1 -17
- package/src/test/api/content-bundle.test.ts +1 -1
- package/src/test/api/enhancement-category.test.ts +5 -5
- package/src/test/api/mission-data.fixture.ts +12 -0
- package/src/test/api/sex.test.ts +33 -1
- package/src/test/api/zone-data.fixture.ts +8 -0
- package/src/test/db/alignment-list.test.ts +200 -0
- package/src/test/db/alternates.test.ts +60 -56
- package/src/test/db/badge-index.test.ts +108 -66
- package/src/test/db/badge-requirement.test.ts +145 -0
- package/src/test/db/badge.test.ts +310 -14
- package/src/test/db/coh-content-database.test.ts +110 -29
- package/src/test/db/contact.test.ts +97 -0
- package/src/test/db/location.test.ts +51 -0
- package/src/test/db/mission.test.ts +171 -0
- package/src/test/db/morality-list.test.ts +457 -0
- package/src/test/db/zone.test.ts +36 -0
- package/src/test/index.test.ts +4 -2
- package/src/test/util.test.ts +112 -22
- package/src/main/api/badge-partial-data.ts +0 -66
- package/src/main/api/badge-partial-type.ts +0 -8
- package/src/main/api/game-map-data.ts +0 -26
- package/src/main/api/plaque-type.ts +0 -6
- package/src/main/api/vidiot-map-data.ts +0 -18
- package/src/main/api/vidiot-map-point-of-interest-data.ts +0 -30
- package/src/main/db/alignments.ts +0 -17
- package/src/main/db/badge-partial.ts +0 -83
- package/src/main/db/game-map.ts +0 -33
- package/src/main/db/vidiot-map-point-of-interest.ts +0 -39
- package/src/main/db/vidiot-map.ts +0 -25
- package/src/test/api/alignments.test.ts +0 -40
- package/src/test/api/badge-partial-data.fixture.ts +0 -17
- package/src/test/api/badge-partial-type.test.ts +0 -31
- package/src/test/api/game-map-data.fixture.ts +0 -10
- package/src/test/api/plaque-type.test.ts +0 -31
- package/src/test/api/vidiot-map-point-of-interest.fixture.ts +0 -10
- package/src/test/api/vidiot-map.fixture.ts +0 -9
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { badgeDataFixture } from '../api/badge-data.fixture'
|
|
2
|
-
import { Badge, BadgeIndex
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const TEST_MAPS = [
|
|
6
|
-
new GameMap(gameMapDataFixture.create({ key: 'atlas-park', name: 'Atlas Park' })),
|
|
7
|
-
new GameMap(gameMapDataFixture.create({ key: 'perez-park', name: 'Perez Park' })),
|
|
8
|
-
new GameMap(gameMapDataFixture.create({ key: 'abandoned-sewer-network', name: 'Abandoned Sewer Network' })),
|
|
9
|
-
]
|
|
2
|
+
import { Badge, BadgeIndex } from '../../main'
|
|
3
|
+
import { badgeRequirementDataFixture } from '../api/badge-requirement-data.fixture'
|
|
10
4
|
|
|
11
5
|
describe(BadgeIndex.name, () => {
|
|
12
6
|
describe('Constructor', () => {
|
|
@@ -26,8 +20,12 @@ describe(BadgeIndex.name, () => {
|
|
|
26
20
|
expect(new BadgeIndex(data).getBadge('foo')).not.toBeUndefined()
|
|
27
21
|
})
|
|
28
22
|
|
|
29
|
-
test(`should
|
|
30
|
-
expect(
|
|
23
|
+
test(`should return undefined for unknown badge`, () => {
|
|
24
|
+
expect(new BadgeIndex([]).getBadge('foo')).toBeUndefined()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test(`should return undefined for undefined key`, () => {
|
|
28
|
+
expect(new BadgeIndex([]).getBadge()).toBeUndefined()
|
|
31
29
|
})
|
|
32
30
|
})
|
|
33
31
|
|
|
@@ -116,10 +114,10 @@ describe(BadgeIndex.name, () => {
|
|
|
116
114
|
|
|
117
115
|
test(`should match on setTitle`, () => {
|
|
118
116
|
const data = [
|
|
119
|
-
new Badge(badgeDataFixture.create({ key: 'match-1',
|
|
120
|
-
new Badge(badgeDataFixture.create({ key: 'match-2',
|
|
121
|
-
new Badge(badgeDataFixture.create({ key: 'miss-1',
|
|
122
|
-
new Badge(badgeDataFixture.create({ key: 'miss-2',
|
|
117
|
+
new Badge(badgeDataFixture.create({ key: 'match-1', setTitleId: [123] })),
|
|
118
|
+
new Badge(badgeDataFixture.create({ key: 'match-2', setTitleId: [456, 123] })),
|
|
119
|
+
new Badge(badgeDataFixture.create({ key: 'miss-1', setTitleId: [456] })),
|
|
120
|
+
new Badge(badgeDataFixture.create({ key: 'miss-2', setTitleId: undefined })),
|
|
123
121
|
]
|
|
124
122
|
|
|
125
123
|
const result = new BadgeIndex(data).searchBadges({ query: { str: '123', on: { setTitle: true } } })
|
|
@@ -185,45 +183,50 @@ describe(BadgeIndex.name, () => {
|
|
|
185
183
|
|
|
186
184
|
test(`should filter on badge type`, () => {
|
|
187
185
|
const data = [
|
|
188
|
-
new Badge(badgeDataFixture.create({ key: 'badge-1', type: '
|
|
189
|
-
new Badge(badgeDataFixture.create({ key: 'badge-2', type: '
|
|
190
|
-
new Badge(badgeDataFixture.create({ key: 'badge-3', type: '
|
|
191
|
-
new Badge(badgeDataFixture.create({ key: 'badge-4', type: '
|
|
192
|
-
new Badge(badgeDataFixture.create({ key: 'badge-5', type: '
|
|
193
|
-
new Badge(badgeDataFixture.create({ key: 'badge-6', type: '
|
|
186
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1', type: 'exploration' })),
|
|
187
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2', type: 'exploration' })),
|
|
188
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3', type: 'history' })),
|
|
189
|
+
new Badge(badgeDataFixture.create({ key: 'badge-4', type: 'history' })),
|
|
190
|
+
new Badge(badgeDataFixture.create({ key: 'badge-5', type: 'accolade' })),
|
|
191
|
+
new Badge(badgeDataFixture.create({ key: 'badge-6', type: 'accolade' })),
|
|
194
192
|
]
|
|
195
193
|
|
|
196
|
-
const result = new BadgeIndex(data).searchBadges({ filter: { type: '
|
|
194
|
+
const result = new BadgeIndex(data).searchBadges({ filter: { type: 'history' } })
|
|
197
195
|
const keys = result.items.map(x => x.key)
|
|
198
196
|
expect(keys).toStrictEqual(['badge-3', 'badge-4'])
|
|
199
197
|
})
|
|
200
198
|
|
|
201
|
-
test(`should filter on badge
|
|
199
|
+
test(`should filter on badge zone`, () => {
|
|
202
200
|
const data = [
|
|
203
|
-
new Badge(badgeDataFixture.create({ key: 'badge-1',
|
|
204
|
-
new Badge(badgeDataFixture.create({ key: 'badge-2',
|
|
205
|
-
new Badge(badgeDataFixture.create({ key: 'badge-3',
|
|
206
|
-
new Badge(badgeDataFixture.create({ key: 'badge-4',
|
|
207
|
-
new Badge(badgeDataFixture.create({
|
|
208
|
-
|
|
201
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
202
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
203
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
204
|
+
new Badge(badgeDataFixture.create({ key: 'badge-4', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
205
|
+
new Badge(badgeDataFixture.create({
|
|
206
|
+
key: 'badge-5', requirements: [
|
|
207
|
+
badgeRequirementDataFixture.create({ location: { zoneKey: 'atlas-park' } }),
|
|
208
|
+
badgeRequirementDataFixture.create({ location: { zoneKey: 'perez-park' } }),
|
|
209
|
+
],
|
|
210
|
+
})),
|
|
211
|
+
new Badge(badgeDataFixture.create({ key: 'badge-6', requirements: [{ location: undefined }] })),
|
|
209
212
|
]
|
|
210
213
|
|
|
211
|
-
const result = new BadgeIndex(data).searchBadges({ filter: {
|
|
214
|
+
const result = new BadgeIndex(data).searchBadges({ filter: { zoneKey: 'perez-park' } })
|
|
212
215
|
const keys = result.items.map(x => x.key)
|
|
213
|
-
expect(keys).toStrictEqual(['badge-2'
|
|
216
|
+
expect(keys).toStrictEqual(['badge-2'])
|
|
214
217
|
})
|
|
215
218
|
|
|
216
|
-
test(`should filter on
|
|
219
|
+
test(`should filter on alignment`, () => {
|
|
217
220
|
const data = [
|
|
218
|
-
new Badge(badgeDataFixture.create({ key: 'badge-1',
|
|
219
|
-
new Badge(badgeDataFixture.create({ key: 'badge-2',
|
|
220
|
-
new Badge(badgeDataFixture.create({ key: 'badge-3',
|
|
221
|
-
new Badge(badgeDataFixture.create({ key: 'badge-4',
|
|
222
|
-
new Badge(badgeDataFixture.create({ key: 'badge-5',
|
|
223
|
-
new Badge(badgeDataFixture.create({ key: 'badge-6',
|
|
221
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1', morality: ['hero'] })),
|
|
222
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2', morality: ['villain'] })),
|
|
223
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3', morality: ['loyalist'] })),
|
|
224
|
+
new Badge(badgeDataFixture.create({ key: 'badge-4', morality: ['hero', 'villain'] })),
|
|
225
|
+
new Badge(badgeDataFixture.create({ key: 'badge-5', morality: ['villain', 'loyalist'] })),
|
|
226
|
+
new Badge(badgeDataFixture.create({ key: 'badge-6', morality: ['hero', 'villain', 'loyalist'] })),
|
|
224
227
|
]
|
|
225
228
|
|
|
226
|
-
const result = new BadgeIndex(data).searchBadges({ filter: {
|
|
229
|
+
const result = new BadgeIndex(data).searchBadges({ filter: { morality: 'hero' } })
|
|
227
230
|
const keys = result.items.map(x => x.key)
|
|
228
231
|
expect(keys).toStrictEqual(['badge-1', 'badge-4', 'badge-6'])
|
|
229
232
|
})
|
|
@@ -359,6 +362,26 @@ describe(BadgeIndex.name, () => {
|
|
|
359
362
|
const result = new BadgeIndex(data).searchBadges()
|
|
360
363
|
expect(result.totalPages).toBe(1)
|
|
361
364
|
})
|
|
365
|
+
|
|
366
|
+
test(`should return the last page if a page is requested past the max`, () => {
|
|
367
|
+
const data = [
|
|
368
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
369
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
370
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
371
|
+
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
372
|
+
new Badge(badgeDataFixture.create({ key: 'badge-5' })),
|
|
373
|
+
]
|
|
374
|
+
|
|
375
|
+
const result = new BadgeIndex(data).searchBadges({ pageSize: 2, page: 10 })
|
|
376
|
+
const keys = result.items.map(x => x.key)
|
|
377
|
+
expect(keys).toStrictEqual(['badge-5'])
|
|
378
|
+
expect(result.page).toBe(3)
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
test(`should return the first page if a page is requested lower than 1`, () => {
|
|
382
|
+
const result = new BadgeIndex([]).searchBadges({ page: -10 })
|
|
383
|
+
expect(result.page).toBe(1)
|
|
384
|
+
})
|
|
362
385
|
})
|
|
363
386
|
|
|
364
387
|
describe('sort', () => {
|
|
@@ -370,7 +393,21 @@ describe(BadgeIndex.name, () => {
|
|
|
370
393
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
371
394
|
]
|
|
372
395
|
|
|
373
|
-
const result = new BadgeIndex(data
|
|
396
|
+
const result = new BadgeIndex(data).searchBadges()
|
|
397
|
+
|
|
398
|
+
const keys = result.items.map(x => x.key)
|
|
399
|
+
expect(keys).toStrictEqual(['badge-1', 'badge-2', 'badge-3', 'badge-4'])
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
test(`should not modify sort if order is canonical`, () => {
|
|
403
|
+
const data = [
|
|
404
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1' })),
|
|
405
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2' })),
|
|
406
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3' })),
|
|
407
|
+
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
408
|
+
]
|
|
409
|
+
|
|
410
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'canonical' } })
|
|
374
411
|
|
|
375
412
|
const keys = result.items.map(x => x.key)
|
|
376
413
|
expect(keys).toStrictEqual(['badge-1', 'badge-2', 'badge-3', 'badge-4'])
|
|
@@ -384,7 +421,7 @@ describe(BadgeIndex.name, () => {
|
|
|
384
421
|
new Badge(badgeDataFixture.create({ key: 'badge-4' })),
|
|
385
422
|
]
|
|
386
423
|
|
|
387
|
-
const result = new BadgeIndex(data
|
|
424
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { dir: 'desc' } })
|
|
388
425
|
|
|
389
426
|
const keys = result.items.map(x => x.key)
|
|
390
427
|
expect(keys).toStrictEqual(['badge-4', 'badge-3', 'badge-2', 'badge-1'])
|
|
@@ -397,7 +434,7 @@ describe(BadgeIndex.name, () => {
|
|
|
397
434
|
new Badge(badgeDataFixture.create({ key: 'badge-3', name: [{ value: 'AAB' }] })),
|
|
398
435
|
]
|
|
399
436
|
|
|
400
|
-
const result = new BadgeIndex(data
|
|
437
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'badge-name' } })
|
|
401
438
|
|
|
402
439
|
const keys = result.items.map(x => x.key)
|
|
403
440
|
expect(keys).toStrictEqual(['badge-3', 'badge-1', 'badge-2'])
|
|
@@ -410,7 +447,7 @@ describe(BadgeIndex.name, () => {
|
|
|
410
447
|
new Badge(badgeDataFixture.create({ key: 'badge-3', name: [{ value: 'AAB' }] })),
|
|
411
448
|
]
|
|
412
449
|
|
|
413
|
-
const result = new BadgeIndex(data
|
|
450
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'badge-name', dir: 'desc' } })
|
|
414
451
|
|
|
415
452
|
const keys = result.items.map(x => x.key)
|
|
416
453
|
expect(keys).toStrictEqual(['badge-2', 'badge-1', 'badge-3'])
|
|
@@ -423,62 +460,67 @@ describe(BadgeIndex.name, () => {
|
|
|
423
460
|
new Badge(badgeDataFixture.create({ key: 'badge-3', name: [{ value: 'AAB' }] })),
|
|
424
461
|
]
|
|
425
462
|
|
|
426
|
-
const result = new BadgeIndex(data
|
|
463
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'badge-name' } })
|
|
427
464
|
|
|
428
465
|
const keys = result.items.map(x => x.key)
|
|
429
466
|
expect(keys).toStrictEqual(['badge-3', 'badge-1', 'badge-2'])
|
|
430
467
|
})
|
|
431
468
|
|
|
432
|
-
test(`should sort by
|
|
469
|
+
test(`should sort by zone name`, () => {
|
|
433
470
|
const data = [
|
|
434
|
-
new Badge(badgeDataFixture.create({ key: 'badge-1',
|
|
435
|
-
new Badge(badgeDataFixture.create({ key: 'badge-2',
|
|
436
|
-
new Badge(badgeDataFixture.create({ key: 'badge-3',
|
|
471
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
472
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
473
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
437
474
|
]
|
|
438
475
|
|
|
439
|
-
const result = new BadgeIndex(data
|
|
476
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key' } })
|
|
440
477
|
|
|
441
478
|
const keys = result.items.map(x => x.key)
|
|
442
479
|
expect(keys).toStrictEqual(['badge-3', 'badge-1', 'badge-2'])
|
|
443
480
|
})
|
|
444
481
|
|
|
445
|
-
test(`should sort by
|
|
482
|
+
test(`should sort by zone name descending`, () => {
|
|
446
483
|
const data = [
|
|
447
|
-
new Badge(badgeDataFixture.create({ key: 'badge-1',
|
|
448
|
-
new Badge(badgeDataFixture.create({ key: 'badge-2',
|
|
449
|
-
new Badge(badgeDataFixture.create({ key: 'badge-3',
|
|
484
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
485
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
486
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
450
487
|
]
|
|
451
488
|
|
|
452
|
-
const result = new BadgeIndex(data
|
|
489
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key', dir: 'desc' } })
|
|
453
490
|
|
|
454
491
|
const keys = result.items.map(x => x.key)
|
|
455
492
|
expect(keys).toStrictEqual(['badge-2', 'badge-1', 'badge-3'])
|
|
456
493
|
})
|
|
457
494
|
|
|
458
|
-
test(`should maintain canonical as secondary sort when sorting by
|
|
495
|
+
test(`should maintain canonical as secondary sort when sorting by zone name`, () => {
|
|
459
496
|
const data = [
|
|
460
|
-
new Badge(badgeDataFixture.create({ key: 'badge-1',
|
|
461
|
-
new Badge(badgeDataFixture.create({ key: 'badge-2',
|
|
462
|
-
new Badge(badgeDataFixture.create({ key: 'badge-3',
|
|
463
|
-
new Badge(badgeDataFixture.create({ key: 'badge-4',
|
|
497
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
498
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
499
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
500
|
+
new Badge(badgeDataFixture.create({ key: 'badge-4', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
464
501
|
]
|
|
465
502
|
|
|
466
|
-
const result = new BadgeIndex(data
|
|
503
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key' } })
|
|
467
504
|
|
|
468
505
|
const keys = result.items.map(x => x.key)
|
|
469
506
|
expect(keys).toStrictEqual(['badge-4', 'badge-1', 'badge-3', 'badge-2'])
|
|
470
507
|
})
|
|
471
508
|
|
|
472
|
-
test(`should sort
|
|
509
|
+
test(`should sort undefined or multiple zone names to the end`, () => {
|
|
473
510
|
const data = [
|
|
474
|
-
new Badge(badgeDataFixture.create({ key: 'badge-1',
|
|
475
|
-
new Badge(badgeDataFixture.create({ key: 'badge-2',
|
|
476
|
-
new Badge(badgeDataFixture.create({ key: 'badge-3',
|
|
477
|
-
new Badge(badgeDataFixture.create({
|
|
478
|
-
|
|
511
|
+
new Badge(badgeDataFixture.create({ key: 'badge-1', requirements: [{ location: { zoneKey: 'atlas-park' } }] })),
|
|
512
|
+
new Badge(badgeDataFixture.create({ key: 'badge-2', requirements: [{ location: undefined }] })),
|
|
513
|
+
new Badge(badgeDataFixture.create({ key: 'badge-3', requirements: [{ location: { zoneKey: 'perez-park' } }] })),
|
|
514
|
+
new Badge(badgeDataFixture.create({
|
|
515
|
+
key: 'badge-4', requirements: [
|
|
516
|
+
badgeRequirementDataFixture.create({ location: { zoneKey: 'atlas-park' } }),
|
|
517
|
+
badgeRequirementDataFixture.create({ location: { zoneKey: 'perez-park' } }),
|
|
518
|
+
],
|
|
519
|
+
})),
|
|
520
|
+
new Badge(badgeDataFixture.create({ key: 'badge-5', requirements: [{ location: { zoneKey: 'abandoned-sewer-network' } }] })),
|
|
479
521
|
]
|
|
480
522
|
|
|
481
|
-
const result = new BadgeIndex(data
|
|
523
|
+
const result = new BadgeIndex(data).searchBadges({ sort: { by: 'zone-key' } })
|
|
482
524
|
|
|
483
525
|
const keys = result.items.map(x => x.key)
|
|
484
526
|
expect(keys).toStrictEqual(['badge-5', 'badge-1', 'badge-3', 'badge-2', 'badge-4'])
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { BadgeRequirement } from '../../main'
|
|
2
|
+
import { badgeRequirementDataFixture } from '../api/badge-requirement-data.fixture'
|
|
3
|
+
|
|
4
|
+
describe(BadgeRequirement.name, () => {
|
|
5
|
+
describe('Constructor', () => {
|
|
6
|
+
test('should accept the test fixture', () => {
|
|
7
|
+
new BadgeRequirement(badgeRequirementDataFixture.create())
|
|
8
|
+
})
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
describe('key', () => {
|
|
12
|
+
test('should be set from the data', () => {
|
|
13
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ key: 'foo' }))
|
|
14
|
+
expect(requirement.key).toEqual('foo')
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('type', () => {
|
|
19
|
+
test('should be set from the data', () => {
|
|
20
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ type: 'badge' }))
|
|
21
|
+
expect(requirement.type).toEqual('badge')
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('location', () => {
|
|
26
|
+
test('should be set from the data', () => {
|
|
27
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ location: { zoneKey: 'foo', coords: [1, 2, 3] } }))
|
|
28
|
+
expect(requirement.location).toStrictEqual([{ zoneKey: 'foo', coords: [1, 2, 3] }])
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('should accept an array', () => {
|
|
32
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({
|
|
33
|
+
location: [
|
|
34
|
+
{ zoneKey: 'foo', coords: [1, 2, 3] },
|
|
35
|
+
{ zoneKey: 'bar', coords: [4, 5, 6] },
|
|
36
|
+
],
|
|
37
|
+
}))
|
|
38
|
+
expect(requirement.location).toStrictEqual([
|
|
39
|
+
{ zoneKey: 'foo', coords: [1, 2, 3] },
|
|
40
|
+
{ zoneKey: 'bar', coords: [4, 5, 6] },
|
|
41
|
+
])
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('should be optional', () => {
|
|
45
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('location').create())
|
|
46
|
+
expect(requirement.location).toBeUndefined()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe('badgeKey', () => {
|
|
51
|
+
test('should be set from the data', () => {
|
|
52
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ badgeKey: 'foo' }))
|
|
53
|
+
expect(requirement.badgeKey).toEqual('foo')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('should be optional', () => {
|
|
57
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('badgeKey').create())
|
|
58
|
+
expect(requirement.badgeKey).toBeUndefined()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('missionKey', () => {
|
|
63
|
+
test('should be set from the data', () => {
|
|
64
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ missionKey: 'foo' }))
|
|
65
|
+
expect(requirement.missionKey).toEqual('foo')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('should be optional', () => {
|
|
69
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('missionKey').create())
|
|
70
|
+
expect(requirement.missionKey).toBeUndefined()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('monumentText', () => {
|
|
75
|
+
test('should be set from the data', () => {
|
|
76
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ monumentText: 'foo' }))
|
|
77
|
+
expect(requirement.monumentText).toEqual('foo')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('should be optional', () => {
|
|
81
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('monumentText').create())
|
|
82
|
+
expect(requirement.monumentText).toBeUndefined()
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('inventionLevel', () => {
|
|
87
|
+
test('should be set from the data', () => {
|
|
88
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ inventionLevel: 10 }))
|
|
89
|
+
expect(requirement.inventionLevel).toEqual(10)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('should be optional', () => {
|
|
93
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('inventionLevel').create())
|
|
94
|
+
expect(requirement.inventionLevel).toBeUndefined()
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('inventionTypes', () => {
|
|
99
|
+
test('should be set from the data', () => {
|
|
100
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ inventionTypes: ['accuracy', 'confuse'] }))
|
|
101
|
+
expect(requirement.inventionTypes).toStrictEqual(['accuracy', 'confuse'])
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('should be optional', () => {
|
|
105
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('inventionTypes').create())
|
|
106
|
+
expect(requirement.inventionTypes).toBeUndefined()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('count', () => {
|
|
111
|
+
test('should be set from the data', () => {
|
|
112
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ count: 5 }))
|
|
113
|
+
expect(requirement.count).toEqual(5)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('should be optional', () => {
|
|
117
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('count').create())
|
|
118
|
+
expect(requirement.count).toBeUndefined()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('notes', () => {
|
|
123
|
+
test('should be set from the data', () => {
|
|
124
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ notes: 'some notes' }))
|
|
125
|
+
expect(requirement.notes).toEqual('some notes')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('should be optional', () => {
|
|
129
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('notes').create())
|
|
130
|
+
expect(requirement.notes).toBeUndefined()
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('links', () => {
|
|
135
|
+
test('should be set from the data', () => {
|
|
136
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ links: [{ title: 'foo', href: 'bar' }] }))
|
|
137
|
+
expect(requirement.links).toStrictEqual([{ title: 'foo', href: 'bar' }])
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('should be optional', () => {
|
|
141
|
+
const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('links').create())
|
|
142
|
+
expect(requirement.links).toHaveLength(0)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
})
|