coh-content-db 2.0.0-rc.4 → 2.0.0-rc.6

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.
Files changed (64) hide show
  1. package/README.md +31 -7
  2. package/dist/coh-content-db.d.ts +353 -185
  3. package/dist/coh-content-db.js +460 -300
  4. package/dist/coh-content-db.js.map +1 -1
  5. package/dist/coh-content-db.mjs +448 -294
  6. package/dist/coh-content-db.mjs.map +1 -1
  7. package/package.json +1 -4
  8. package/src/main/api/alternate-data.ts +2 -2
  9. package/src/main/api/badge-data.ts +21 -19
  10. package/src/main/api/badge-requirement-data.ts +82 -0
  11. package/src/main/api/badge-requirement-type.ts +11 -0
  12. package/src/main/api/change.ts +5 -2
  13. package/src/main/api/contact-data.ts +46 -0
  14. package/src/main/api/content-bundle.ts +12 -7
  15. package/src/main/api/markdown-string.ts +4 -0
  16. package/src/main/api/zone-data.ts +20 -0
  17. package/src/main/changelog.ts +7 -2
  18. package/src/main/db/alignments.ts +17 -0
  19. package/src/main/db/alternates.ts +8 -14
  20. package/src/main/db/badge-index.ts +93 -0
  21. package/src/main/db/badge-requirement.ts +102 -0
  22. package/src/main/db/badge-search-options.ts +51 -0
  23. package/src/main/db/badge.ts +55 -48
  24. package/src/main/db/bundle-metadata.ts +5 -6
  25. package/src/main/db/coh-content-database.ts +65 -40
  26. package/src/main/db/contact.ts +59 -0
  27. package/src/main/db/paged.ts +7 -0
  28. package/src/main/db/zone.ts +28 -0
  29. package/src/main/index.ts +15 -11
  30. package/src/main/util.ts +68 -7
  31. package/src/test/api/alignments.test.ts +40 -0
  32. package/src/test/api/badge-data.fixture.ts +9 -7
  33. package/src/test/api/badge-requirement-data.fixture.ts +17 -0
  34. package/src/test/api/badge-requirement-type.test.ts +31 -0
  35. package/src/test/api/contact-data.fixture.ts +13 -0
  36. package/src/test/api/content-bundle.fixture.ts +2 -2
  37. package/src/test/api/content-bundle.test.ts +1 -1
  38. package/src/test/api/zone-data.fixture.ts +8 -0
  39. package/src/test/db/alternates.test.ts +16 -74
  40. package/src/test/db/badge-index.test.ts +520 -0
  41. package/src/test/db/badge-requirement.test.ts +180 -0
  42. package/src/test/db/badge.test.ts +190 -15
  43. package/src/test/db/coh-content-database.test.ts +125 -18
  44. package/src/test/db/contact.test.ts +96 -0
  45. package/src/test/db/zone.test.ts +36 -0
  46. package/src/test/index.test.ts +6 -2
  47. package/src/test/util.test.ts +91 -18
  48. package/src/main/api/badge-partial-data.ts +0 -65
  49. package/src/main/api/badge-partial-type.ts +0 -8
  50. package/src/main/api/game-map-data.ts +0 -26
  51. package/src/main/api/vidiot-map-data.ts +0 -18
  52. package/src/main/api/vidiot-map-point-of-interest-data.ts +0 -30
  53. package/src/main/db/badge-partial.ts +0 -35
  54. package/src/main/db/badge-search-document.ts +0 -16
  55. package/src/main/db/game-map.ts +0 -33
  56. package/src/main/db/vidiot-map-point-of-interest.ts +0 -40
  57. package/src/main/db/vidiot-map.ts +0 -25
  58. package/src/test/api/badge-partial-data.fixture.ts +0 -17
  59. package/src/test/api/badge-partial-type.test.ts +0 -31
  60. package/src/test/api/game-map-data.fixture.ts +0 -10
  61. package/src/test/api/vidiot-map-point-of-interest.fixture.ts +0 -10
  62. package/src/test/api/vidiot-map.fixture.ts +0 -9
  63. package/src/test/db/badge-search-document.test.ts +0 -35
  64. package/src/test/db/coh-content-database-search.test.ts +0 -119
@@ -0,0 +1,180 @@
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('zoneKey', () => {
26
+ test('should be set from the data', () => {
27
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ zoneKey: 'zone123' }))
28
+ expect(requirement.zoneKey).toEqual('zone123')
29
+ })
30
+
31
+ test('should be optional', () => {
32
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('zoneKey').create())
33
+ expect(requirement.zoneKey).toBeUndefined()
34
+ })
35
+ })
36
+
37
+ describe('loc', () => {
38
+ test('should be set from the data', () => {
39
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ loc: [1, 2, 3] }))
40
+ expect(requirement.loc).toStrictEqual([1, 2, 3])
41
+ })
42
+
43
+ test('should be optional', () => {
44
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('loc').create())
45
+ expect(requirement.loc).toBeUndefined()
46
+ })
47
+ })
48
+
49
+ describe('plaqueType', () => {
50
+ test('should be set from the data', () => {
51
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ plaqueType: 'MONUMENT' }))
52
+ expect(requirement.plaqueType).toEqual('MONUMENT')
53
+ })
54
+
55
+ test('should be optional', () => {
56
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('plaqueType').create())
57
+ expect(requirement.plaqueType).toBeUndefined()
58
+ })
59
+ })
60
+
61
+ describe('plaqueInscription', () => {
62
+ test('should be set from the data', () => {
63
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ plaqueInscription: 'foo' }))
64
+ expect(requirement.plaqueInscription).toEqual('foo')
65
+ })
66
+
67
+ test('should be optional', () => {
68
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('plaqueInscription').create())
69
+ expect(requirement.plaqueInscription).toBeUndefined()
70
+ })
71
+ })
72
+
73
+ describe('vidiotMapKey', () => {
74
+ test('should be set from the data', () => {
75
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ vidiotMapKey: 'A1' }))
76
+ expect(requirement.vidiotMapKey).toEqual('A1')
77
+ })
78
+
79
+ test('should be optional', () => {
80
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('vidiotMapKey').create())
81
+ expect(requirement.vidiotMapKey).toBeUndefined()
82
+ })
83
+ })
84
+
85
+ describe('badgeKey', () => {
86
+ test('should be set from the data', () => {
87
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ badgeKey: 'foo' }))
88
+ expect(requirement.badgeKey).toEqual('foo')
89
+ })
90
+
91
+ test('should be optional', () => {
92
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('badgeKey').create())
93
+ expect(requirement.badgeKey).toBeUndefined()
94
+ })
95
+ })
96
+
97
+ describe('missionName', () => {
98
+ test('should be set from the data', () => {
99
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ missionName: 'foo' }))
100
+ expect(requirement.missionName).toEqual('foo')
101
+ })
102
+
103
+ test('should be optional', () => {
104
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('missionName').create())
105
+ expect(requirement.missionName).toBeUndefined()
106
+ })
107
+ })
108
+
109
+ describe('contactKey', () => {
110
+ test('should be set from the data', () => {
111
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ contactKey: 'foo' }))
112
+ expect(requirement.contactKey).toEqual('foo')
113
+ })
114
+
115
+ test('should be optional', () => {
116
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('contactKey').create())
117
+ expect(requirement.contactKey).toBeUndefined()
118
+ })
119
+ })
120
+
121
+ describe('inventionLevel', () => {
122
+ test('should be set from the data', () => {
123
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ inventionLevel: 10 }))
124
+ expect(requirement.inventionLevel).toEqual(10)
125
+ })
126
+
127
+ test('should be optional', () => {
128
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('inventionLevel').create())
129
+ expect(requirement.inventionLevel).toBeUndefined()
130
+ })
131
+ })
132
+
133
+ describe('inventionTypes', () => {
134
+ test('should be set from the data', () => {
135
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ inventionTypes: ['ACCURACY', 'CONFUSE'] }))
136
+ expect(requirement.inventionTypes).toStrictEqual(['ACCURACY', 'CONFUSE'])
137
+ })
138
+
139
+ test('should be optional', () => {
140
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('inventionTypes').create())
141
+ expect(requirement.inventionTypes).toBeUndefined()
142
+ })
143
+ })
144
+
145
+ describe('inventionCount', () => {
146
+ test('should be set from the data', () => {
147
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ inventionCount: 5 }))
148
+ expect(requirement.inventionCount).toEqual(5)
149
+ })
150
+
151
+ test('should be optional', () => {
152
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('inventionCount').create())
153
+ expect(requirement.inventionCount).toBeUndefined()
154
+ })
155
+ })
156
+
157
+ describe('notes', () => {
158
+ test('should be set from the data', () => {
159
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ notes: 'some notes' }))
160
+ expect(requirement.notes).toEqual('some notes')
161
+ })
162
+
163
+ test('should be optional', () => {
164
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('notes').create())
165
+ expect(requirement.notes).toBeUndefined()
166
+ })
167
+ })
168
+
169
+ describe('links', () => {
170
+ test('should be set from the data', () => {
171
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.create({ links: [{ title: 'foo', href: 'bar' }] }))
172
+ expect(requirement.links).toStrictEqual([{ title: 'foo', href: 'bar' }])
173
+ })
174
+
175
+ test('should be optional', () => {
176
+ const requirement = new BadgeRequirement(badgeRequirementDataFixture.omit('links').create())
177
+ expect(requirement.links).toHaveLength(0)
178
+ })
179
+ })
180
+ })
@@ -1,6 +1,6 @@
1
1
  import { Badge } from '../../main'
2
2
  import { badgeDataFixture } from '../api/badge-data.fixture'
3
- import { badgePartialDataFixture } from '../api/badge-partial-data.fixture'
3
+ import { badgeRequirementDataFixture } from '../api/badge-requirement-data.fixture'
4
4
 
5
5
  describe(Badge.name, () => {
6
6
  describe('Constructor', () => {
@@ -9,33 +9,208 @@ describe(Badge.name, () => {
9
9
  })
10
10
  })
11
11
 
12
- describe('partials', () => {
13
- test(`should throw an error on duplicate key`, () => {
12
+ describe('key', () => {
13
+ test('should be set from the data', () => {
14
+ const badge = new Badge(badgeDataFixture.create({ key: 'badge123' }))
15
+ expect(badge.key).toEqual('badge123')
16
+ })
17
+ })
18
+
19
+ describe('type', () => {
20
+ test('should be set from the data', () => {
21
+ const badge = new Badge(badgeDataFixture.create({ type: 'ACHIEVEMENT' }))
22
+ expect(badge.type).toEqual('ACHIEVEMENT')
23
+ })
24
+ })
25
+
26
+ describe('name', () => {
27
+ test('should be set from the data', () => {
28
+ const badge = new Badge(badgeDataFixture.create({ name: [{ value: 'foo' }] }))
29
+ expect(badge.name.default).toEqual({ value: 'foo' })
30
+ })
31
+ })
32
+
33
+ describe('alignment', () => {
34
+ test('should be set from the data', () => {
35
+ const badge = new Badge(badgeDataFixture.create({ alignment: ['H', 'V'] }))
36
+ expect(badge.alignment.hero).toBeTruthy()
37
+ expect(badge.alignment.villain).toBeTruthy()
38
+ expect(badge.alignment.praetorian).toBeFalsy()
39
+ })
40
+ })
41
+
42
+ describe('badgeText', () => {
43
+ test('should be set from the data', () => {
44
+ const badge = new Badge(badgeDataFixture.create({ badgeText: [{ value: 'foo' }] }))
45
+ expect(badge.badgeText.default).toEqual({ value: 'foo' })
46
+ })
47
+
48
+ test('should be optional', () => {
49
+ const badge = new Badge(badgeDataFixture.omit('badgeText').create())
50
+ expect(badge.badgeText.default).toBeUndefined()
51
+ })
52
+ })
53
+
54
+ describe('acquisition', () => {
55
+ test('should be set from the data', () => {
56
+ const badge = new Badge(badgeDataFixture.create({ acquisition: 'Quest Reward' }))
57
+ expect(badge.acquisition).toEqual('Quest Reward')
58
+ })
59
+
60
+ test('should be optional', () => {
61
+ const badge = new Badge(badgeDataFixture.omit('acquisition').create())
62
+ expect(badge.acquisition).toBeUndefined()
63
+ })
64
+ })
65
+
66
+ describe('icon', () => {
67
+ test('should be set from the data', () => {
68
+ const badge = new Badge(badgeDataFixture.create({ icon: [{ value: 'foo' }] }))
69
+ expect(badge.icon.default).toEqual({ value: 'foo' })
70
+ })
71
+
72
+ test('should be optional', () => {
73
+ const badge = new Badge(badgeDataFixture.omit('icon').create())
74
+ expect(badge.icon.default).toBeUndefined()
75
+ })
76
+ })
77
+
78
+ describe('notes', () => {
79
+ test('should be set from the data', () => {
80
+ const badge = new Badge(badgeDataFixture.create({ notes: 'foo' }))
81
+ expect(badge.notes).toEqual('foo')
82
+ })
83
+
84
+ test('should be optional', () => {
85
+ const badge = new Badge(badgeDataFixture.omit('notes').create())
86
+ expect(badge.notes).toBeUndefined()
87
+ })
88
+ })
89
+
90
+ describe('links', () => {
91
+ test('should be set from the data', () => {
92
+ const badge = new Badge(badgeDataFixture.create({ links: [{ title: 'foo', href: 'bar' }] }))
93
+ expect(badge.links).toStrictEqual([{ title: 'foo', href: 'bar' }])
94
+ })
95
+
96
+ test('should be optional', () => {
97
+ const badge = new Badge(badgeDataFixture.omit('links').create())
98
+ expect(badge.links).toHaveLength(0)
99
+ })
100
+ })
101
+
102
+ describe('zoneKey', () => {
103
+ test('should be set from the data', () => {
104
+ const badge = new Badge(badgeDataFixture.create({ zoneKey: 'foo' }))
105
+ expect(badge.zoneKey).toEqual('foo')
106
+ })
107
+
108
+ test('should be optional', () => {
109
+ const badge = new Badge(badgeDataFixture.omit('zoneKey').create())
110
+ expect(badge.zoneKey).toBeUndefined()
111
+ })
112
+ })
113
+
114
+ describe('loc', () => {
115
+ test('should be set from the data', () => {
116
+ const badge = new Badge(badgeDataFixture.create({ loc: [1, 2, 3] }))
117
+ expect(badge.loc).toStrictEqual([1, 2, 3])
118
+ })
119
+
120
+ test('should be optional', () => {
121
+ const badge = new Badge(badgeDataFixture.omit('loc').create())
122
+ expect(badge.loc).toBeUndefined()
123
+ })
124
+ })
125
+
126
+ describe('effect', () => {
127
+ test('should be set from the data', () => {
128
+ const badge = new Badge(badgeDataFixture.create({ effect: 'foo' }))
129
+ expect(badge.effect).toEqual('foo')
130
+ })
131
+
132
+ test('should be optional', () => {
133
+ const badge = new Badge(badgeDataFixture.omit('effect').create())
134
+ expect(badge.effect).toBeUndefined()
135
+ })
136
+ })
137
+
138
+ describe('vidiotMapKey', () => {
139
+ test('should be set from the data', () => {
140
+ const badge = new Badge(badgeDataFixture.create({ vidiotMapKey: 'foo' }))
141
+ expect(badge.vidiotMapKey).toEqual('foo')
142
+ })
143
+
144
+ test('should be optional', () => {
145
+ const badge = new Badge(badgeDataFixture.omit('vidiotMapKey').create())
146
+ expect(badge.vidiotMapKey).toBeUndefined()
147
+ })
148
+ })
149
+
150
+ describe('setTitle', () => {
151
+ test('should be set from the data', () => {
152
+ const badge = new Badge(badgeDataFixture.create({ setTitle: { id: 123, praetorianId: 456 } }))
153
+ expect(badge.setTitle).toStrictEqual({ id: 123, praetorianId: 456 })
154
+ })
155
+
156
+ test('should be optional', () => {
157
+ const badge = new Badge(badgeDataFixture.omit('setTitle').create())
158
+ expect(badge.setTitle).toBeUndefined()
159
+ })
160
+ })
161
+
162
+ describe('ignoreInTotals', () => {
163
+ test('should be set from the data', () => {
164
+ const badge = new Badge(badgeDataFixture.create({ ignoreInTotals: true }))
165
+ expect(badge.ignoreInTotals).toEqual(true)
166
+ })
167
+
168
+ test('should default to false', () => {
169
+ const badge = new Badge(badgeDataFixture.omit('ignoreInTotals').create())
170
+ expect(badge.ignoreInTotals).toEqual(false)
171
+ })
172
+ })
173
+
174
+ describe('requirements', () => {
175
+ test(`should throw an error on duplicate key in same group`, () => {
176
+ const data = badgeDataFixture.create({
177
+ key: 'badge',
178
+ requirements: [[
179
+ badgeRequirementDataFixture.create({ key: 'foo' }),
180
+ badgeRequirementDataFixture.create({ key: 'foo' }),
181
+ ]],
182
+ })
183
+ expect(() => new Badge(data)).toThrow('Duplicate badge requirement key [badge:foo] in group [1]')
184
+ })
185
+
186
+ test(`should not throw an error on duplicate key in different group`, () => {
14
187
  const data = badgeDataFixture.create({
15
- partials: [
16
- badgePartialDataFixture.create({ key: 'foo' }),
17
- badgePartialDataFixture.create({ key: 'foo' }),
18
- ],
188
+ key: 'badge',
189
+ requirements: [[
190
+ badgeRequirementDataFixture.create({ key: 'foo' }),
191
+ ], [
192
+ badgeRequirementDataFixture.create({ key: 'foo' }),
193
+ ]],
19
194
  })
20
- expect(() => new Badge(data)).toThrow('Duplicate badge partial key [foo]')
195
+ new Badge(data)
21
196
  })
22
197
  })
23
198
 
24
- describe('getBadgePartial', () => {
25
- test(`should retrieve partial from the index`, () => {
199
+ describe('getRequirement', () => {
200
+ test(`should retrieve requirement from the index`, () => {
26
201
  const data = badgeDataFixture.create({
27
- partials: [badgePartialDataFixture.create({ key: 'foo' })],
202
+ requirements: [[badgeRequirementDataFixture.create({ key: 'foo' })]],
28
203
  })
29
204
 
30
- expect(new Badge(data).getPartial('foo')).not.toBeUndefined()
205
+ expect(new Badge(data).getRequirement('foo')).not.toBeUndefined()
31
206
  })
32
207
 
33
- test(`should throw error for unknown partial`, () => {
208
+ test(`should throw error for unknown requirement`, () => {
34
209
  const data = badgeDataFixture.create({
35
- partials: [],
210
+ requirements: [],
36
211
  })
37
212
 
38
- expect(() => new Badge(data).getPartial('foo')).toThrow('Unknown badge partial key [foo]')
213
+ expect(() => new Badge(data).getRequirement('foo')).toThrow('Unknown badge requirement key [foo]')
39
214
  })
40
215
  })
41
216
  })
@@ -2,7 +2,8 @@ import { CohContentDatabase } from '../../main'
2
2
  import { contentBundleFixture } from '../api/content-bundle.fixture'
3
3
  import { archetypeDataFixture } from '../api/archetype-data.fixture'
4
4
  import { badgeDataFixture } from '../api/badge-data.fixture'
5
- import { gameMapDataFixture } from '../api/game-map-data.fixture'
5
+ import { zoneDataFixture } from '../api/zone-data.fixture'
6
+ import { contactDataFixture } from '../api/contact-data.fixture'
6
7
 
7
8
  describe(CohContentDatabase.name, () => {
8
9
  test('should load a basic bundle', () => {
@@ -32,7 +33,7 @@ describe(CohContentDatabase.name, () => {
32
33
  archetypeDataFixture.create({ key: 'foo' }),
33
34
  ],
34
35
  })
35
- expect(() => new CohContentDatabase(data)).toThrow('Duplicate archetype key [foo]')
36
+ expect(() => new CohContentDatabase(data)).toThrow(`Duplicate archetype key 'foo'`)
36
37
  })
37
38
 
38
39
  test(`should accept an undefined field`, () => {
@@ -68,22 +69,41 @@ describe(CohContentDatabase.name, () => {
68
69
  })
69
70
  })
70
71
 
71
- describe('maps', () => {
72
- test(`should throw an error on duplicate map`, () => {
72
+ describe('zones', () => {
73
+ test(`should throw an error on duplicate zone`, () => {
73
74
  const data = contentBundleFixture.create({
74
- maps: [
75
- gameMapDataFixture.create({ key: 'foo' }),
76
- gameMapDataFixture.create({ key: 'foo' }),
75
+ zones: [
76
+ zoneDataFixture.create({ key: 'foo' }),
77
+ zoneDataFixture.create({ key: 'foo' }),
77
78
  ],
78
79
  })
79
- expect(() => new CohContentDatabase(data)).toThrow('Duplicate map key [foo]')
80
+ expect(() => new CohContentDatabase(data)).toThrow(`Duplicate zone key 'foo'`)
80
81
  })
81
82
 
82
83
  test(`should accept an undefined field`, () => {
83
84
  const data = contentBundleFixture
84
- .omit('maps')
85
+ .omit('zones')
85
86
  .create()
86
- expect(() => new CohContentDatabase(data).maps).toHaveLength(0)
87
+ expect(() => new CohContentDatabase(data).zones).toHaveLength(0)
88
+ })
89
+ })
90
+
91
+ describe('contacts', () => {
92
+ test(`should throw an error on duplicate contact`, () => {
93
+ const data = contentBundleFixture.create({
94
+ contacts: [
95
+ contactDataFixture.create({ key: 'foo' }),
96
+ contactDataFixture.create({ key: 'foo' }),
97
+ ],
98
+ })
99
+ expect(() => new CohContentDatabase(data)).toThrow(`Duplicate contact key 'foo'`)
100
+ })
101
+
102
+ test(`should accept an undefined field`, () => {
103
+ const data = contentBundleFixture
104
+ .omit('contacts')
105
+ .create()
106
+ expect(() => new CohContentDatabase(data).contacts).toHaveLength(0)
87
107
  })
88
108
  })
89
109
 
@@ -101,25 +121,79 @@ describe(CohContentDatabase.name, () => {
101
121
  archetypes: [],
102
122
  })
103
123
 
104
- expect(() => new CohContentDatabase(data).getArchetype('foo')).toThrow('Unknown archetype key [foo]')
124
+ expect(() => new CohContentDatabase(data).getArchetype('foo')).toThrow(`Unknown archetype key 'foo'`)
125
+ })
126
+ })
127
+
128
+ describe('getZone', () => {
129
+ test(`should retrieve zone from the index`, () => {
130
+ const data = contentBundleFixture.create({
131
+ zones: [zoneDataFixture.create({ key: 'foo' })],
132
+ })
133
+
134
+ expect(new CohContentDatabase(data).getZone('foo')).not.toBeUndefined()
135
+ })
136
+
137
+ test(`should throw error for unknown zone`, () => {
138
+ const data = contentBundleFixture.create({
139
+ zones: [],
140
+ })
141
+
142
+ expect(() => new CohContentDatabase(data).getZone('foo')).toThrow(`Unknown zone key 'foo'`)
143
+ })
144
+ })
145
+
146
+ describe('zoneExists', () => {
147
+ test(`should return true for a zone that exists`, () => {
148
+ const data = contentBundleFixture.create({
149
+ zones: [zoneDataFixture.create({ key: 'foo' })],
150
+ })
151
+
152
+ expect(new CohContentDatabase(data).zoneExists('foo')).toBeTruthy()
153
+ })
154
+
155
+ test(`should return false for a zone that does not exist`, () => {
156
+ const data = contentBundleFixture.create({
157
+ zones: [],
158
+ })
159
+
160
+ expect(new CohContentDatabase(data).zoneExists('foo')).toBeFalsy()
105
161
  })
106
162
  })
107
163
 
108
- describe('getMap', () => {
109
- test(`should retrieve map from the index`, () => {
164
+ describe('getContact', () => {
165
+ test(`should retrieve contact from the index`, () => {
110
166
  const data = contentBundleFixture.create({
111
- maps: [gameMapDataFixture.create({ key: 'foo' })],
167
+ contacts: [contactDataFixture.create({ key: 'foo' })],
112
168
  })
113
169
 
114
- expect(new CohContentDatabase(data).getMap('foo')).not.toBeUndefined()
170
+ expect(new CohContentDatabase(data).getContact('foo')).not.toBeUndefined()
115
171
  })
116
172
 
117
- test(`should throw error for unknown map`, () => {
173
+ test(`should throw error for unknown contact`, () => {
118
174
  const data = contentBundleFixture.create({
119
- maps: [],
175
+ contacts: [],
120
176
  })
121
177
 
122
- expect(() => new CohContentDatabase(data).getMap('foo')).toThrow('Unknown map key [foo]')
178
+ expect(() => new CohContentDatabase(data).getContact('foo')).toThrow(`Unknown contact key 'foo'`)
179
+ })
180
+ })
181
+
182
+ describe('contactExists', () => {
183
+ test(`should return true for a contact that exists`, () => {
184
+ const data = contentBundleFixture.create({
185
+ contacts: [contactDataFixture.create({ key: 'foo' })],
186
+ })
187
+
188
+ expect(new CohContentDatabase(data).contactExists('foo')).toBeTruthy()
189
+ })
190
+
191
+ test(`should return false for a contact that does not exist`, () => {
192
+ const data = contentBundleFixture.create({
193
+ contacts: [],
194
+ })
195
+
196
+ expect(new CohContentDatabase(data).contactExists('foo')).toBeFalsy()
123
197
  })
124
198
  })
125
199
 
@@ -140,4 +214,37 @@ describe(CohContentDatabase.name, () => {
140
214
  expect(() => new CohContentDatabase(data).getBadge('foo')).toThrow('Unknown badge key [foo]')
141
215
  })
142
216
  })
217
+
218
+ describe('badgeExists', () => {
219
+ test(`should return true for a badge that exists`, () => {
220
+ const data = contentBundleFixture.create({
221
+ badges: [badgeDataFixture.create({ key: 'foo' })],
222
+ })
223
+
224
+ expect(new CohContentDatabase(data).badgeExists('foo')).toBeTruthy()
225
+ })
226
+
227
+ test(`should return false for a badge that does not exist`, () => {
228
+ const data = contentBundleFixture.create({
229
+ badges: [],
230
+ })
231
+
232
+ expect(new CohContentDatabase(data).badgeExists('foo')).toBeFalsy()
233
+ })
234
+ })
235
+
236
+ describe('searchBadges', () => {
237
+ test(`should search the badge list`, () => {
238
+ const data = contentBundleFixture.create({
239
+ badges: [
240
+ badgeDataFixture.create({ key: 'foo', name: [{ value: 'Foo' }] }),
241
+ badgeDataFixture.create({ key: 'bar', name: [{ value: 'Bar' }] }),
242
+ ],
243
+ })
244
+
245
+ const result = new CohContentDatabase(data).searchBadges({ query: { str: 'oo' } })
246
+ expect(result.totalItems).toBe(1)
247
+ expect(result.items.map(x => x.key)).toStrictEqual(['foo'])
248
+ })
249
+ })
143
250
  })