coh-content-db 1.4.1 → 2.0.0-rc.10

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 (101) hide show
  1. package/.editorconfig +24 -0
  2. package/.github/workflows/build.yml +38 -0
  3. package/.github/workflows/pull-request.yml +32 -0
  4. package/.github/workflows/release.yml +52 -0
  5. package/CHANGELOG.md +42 -0
  6. package/LICENSE +24 -674
  7. package/README.md +101 -16
  8. package/dist/coh-content-db.d.ts +988 -22
  9. package/dist/coh-content-db.js +1044 -2
  10. package/dist/coh-content-db.js.map +1 -0
  11. package/dist/coh-content-db.mjs +1009 -0
  12. package/dist/coh-content-db.mjs.map +1 -0
  13. package/eslint.config.mjs +31 -0
  14. package/jest.config.mjs +7 -0
  15. package/package.json +31 -23
  16. package/rollup.config.mjs +27 -0
  17. package/src/main/api/alignment.ts +19 -0
  18. package/src/main/api/alternate-data.ts +22 -0
  19. package/src/main/api/archetype-data.ts +5 -0
  20. package/src/main/api/badge-data.ts +81 -0
  21. package/src/main/api/badge-requirement-data.ts +64 -0
  22. package/src/main/api/badge-requirement-type.ts +32 -0
  23. package/src/main/api/badge-type.ts +19 -0
  24. package/src/main/api/bundle-data.ts +47 -0
  25. package/src/main/api/bundle-header-data.ts +37 -0
  26. package/src/main/api/contact-data.ts +48 -0
  27. package/src/main/api/enhancement-category.ts +30 -0
  28. package/src/main/api/link.ts +4 -0
  29. package/src/main/api/location-data.ts +28 -0
  30. package/src/main/api/markdown-string.ts +4 -0
  31. package/src/main/api/mission-data.ts +83 -0
  32. package/src/main/api/mission-type.ts +2 -0
  33. package/src/main/api/morality.ts +31 -0
  34. package/src/main/api/sex.ts +10 -0
  35. package/src/main/api/zone-data.ts +20 -0
  36. package/src/main/db/abstract-index.ts +37 -0
  37. package/src/main/db/alignment-list.ts +54 -0
  38. package/src/main/db/alternates.ts +67 -0
  39. package/src/main/db/archetype.ts +14 -0
  40. package/src/main/db/badge-index.ts +57 -0
  41. package/src/main/db/badge-requirement.ts +81 -0
  42. package/src/main/db/badge-search-options.ts +51 -0
  43. package/src/main/db/badge.ts +147 -0
  44. package/src/main/db/bundle-header.ts +44 -0
  45. package/src/main/db/coh-content-database.ts +138 -0
  46. package/src/main/db/contact.ts +62 -0
  47. package/src/main/db/key.ts +18 -0
  48. package/src/main/db/location.ts +30 -0
  49. package/src/main/db/mission.ts +107 -0
  50. package/src/main/db/morality-list.ts +99 -0
  51. package/src/main/db/paged.ts +7 -0
  52. package/src/main/db/zone.ts +28 -0
  53. package/src/main/index.ts +41 -0
  54. package/src/main/util.ts +118 -0
  55. package/src/test/api/alignment.test.ts +65 -0
  56. package/src/test/api/archetype-data.fixture.ts +8 -0
  57. package/src/test/api/badge-data.fixture.ts +8 -0
  58. package/src/test/api/badge-data.test.ts +15 -0
  59. package/src/test/api/badge-requirement-data.fixture.ts +7 -0
  60. package/src/test/api/badge-requirement-type.test.ts +31 -0
  61. package/src/test/api/badge-type.test.ts +35 -0
  62. package/src/test/api/bundle-data.fixture.ts +6 -0
  63. package/src/test/api/bundle-header-data.fixture.ts +6 -0
  64. package/src/test/api/contact-data.fixture.ts +7 -0
  65. package/src/test/api/enhancement-category.test.ts +35 -0
  66. package/src/test/api/mission-data.fixture.ts +12 -0
  67. package/src/test/api/sex.test.ts +63 -0
  68. package/src/test/api/zone-data.fixture.ts +8 -0
  69. package/src/test/db/abstract-index.test.ts +55 -0
  70. package/src/test/db/alignment-list.test.ts +200 -0
  71. package/src/test/db/alternates.test.ts +188 -0
  72. package/src/test/db/archetype.test.ts +38 -0
  73. package/src/test/db/badge-index.test.ts +519 -0
  74. package/src/test/db/badge-requirement.test.ts +145 -0
  75. package/src/test/db/badge.test.ts +337 -0
  76. package/src/test/db/bundle-header.test.ts +76 -0
  77. package/src/test/db/coh-content-database.test.ts +282 -0
  78. package/src/test/db/contact.test.ts +97 -0
  79. package/src/test/db/key.test.ts +22 -0
  80. package/src/test/db/location.test.ts +51 -0
  81. package/src/test/db/mission.test.ts +171 -0
  82. package/src/test/db/morality-list.test.ts +457 -0
  83. package/src/test/db/zone.test.ts +36 -0
  84. package/src/test/integration.test.ts +16 -0
  85. package/src/test/util.test.ts +165 -0
  86. package/tsconfig.json +117 -0
  87. package/dist/_changelog.d.ts +0 -3
  88. package/dist/coh-content-db.nomin.js +0 -635
  89. package/dist/content-refence-utils.d.ts +0 -4
  90. package/dist/index.d.ts +0 -8
  91. package/dist/internal/_common.d.ts +0 -4
  92. package/dist/internal/archetype.d.ts +0 -10
  93. package/dist/internal/badge.d.ts +0 -44
  94. package/dist/internal/game-map.d.ts +0 -33
  95. package/dist/internal/server-group.d.ts +0 -24
  96. package/dist/types/archetype.d.ts +0 -9
  97. package/dist/types/badge.d.ts +0 -192
  98. package/dist/types/enhancement.d.ts +0 -28
  99. package/dist/types/game-map.d.ts +0 -47
  100. package/dist/types/link.d.ts +0 -4
  101. package/dist/types/server-group.d.ts +0 -75
@@ -0,0 +1,337 @@
1
+ import { Badge, compareByDefaultName, compareByZoneKey } from '../../main'
2
+ import { badgeDataFixture } from '../api/badge-data.fixture'
3
+ import { badgeRequirementDataFixture } from '../api/badge-requirement-data.fixture'
4
+
5
+ describe(Badge.name, () => {
6
+ describe('Constructor', () => {
7
+ test(`should accept the test fixture`, () => {
8
+ new Badge(badgeDataFixture.create())
9
+ })
10
+ })
11
+
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('morality', () => {
34
+ test('should be set from the data', () => {
35
+ const badge = new Badge(badgeDataFixture.create({ morality: ['hero', 'villain'] }))
36
+ expect(badge.morality.hero).toBeTruthy()
37
+ expect(badge.morality.villain).toBeTruthy()
38
+ })
39
+
40
+ test('should accept a single string', () => {
41
+ const badge = new Badge(badgeDataFixture.create({ morality: 'hero' }))
42
+ expect(badge.morality.hero).toBeTruthy()
43
+ expect(badge.morality.villain).toBeFalsy()
44
+ })
45
+
46
+ test('should be optional, defaulting to all', () => {
47
+ const badge = new Badge(badgeDataFixture.omit('morality').create())
48
+ expect(badge.morality.all).toBeTruthy()
49
+ })
50
+ })
51
+
52
+ describe('badgeText', () => {
53
+ test('should be set from the data', () => {
54
+ const badge = new Badge(badgeDataFixture.create({ badgeText: [{ value: 'foo' }] }))
55
+ expect(badge.badgeText.default).toEqual({ value: 'foo' })
56
+ })
57
+
58
+ test('should be optional', () => {
59
+ const badge = new Badge(badgeDataFixture.omit('badgeText').create())
60
+ expect(badge.badgeText.default).toBeUndefined()
61
+ })
62
+ })
63
+
64
+ describe('acquisition', () => {
65
+ test('should be set from the data', () => {
66
+ const badge = new Badge(badgeDataFixture.create({ acquisition: 'Quest Reward' }))
67
+ expect(badge.acquisition).toEqual('Quest Reward')
68
+ })
69
+
70
+ test('should be optional', () => {
71
+ const badge = new Badge(badgeDataFixture.omit('acquisition').create())
72
+ expect(badge.acquisition).toBeUndefined()
73
+ })
74
+ })
75
+
76
+ describe('icon', () => {
77
+ test('should be set from the data', () => {
78
+ const badge = new Badge(badgeDataFixture.create({ icon: [{ value: 'foo' }] }))
79
+ expect(badge.icon.default).toEqual({ value: 'foo' })
80
+ })
81
+
82
+ test('should be optional', () => {
83
+ const badge = new Badge(badgeDataFixture.omit('icon').create())
84
+ expect(badge.icon.default).toBeUndefined()
85
+ })
86
+ })
87
+
88
+ describe('notes', () => {
89
+ test('should be set from the data', () => {
90
+ const badge = new Badge(badgeDataFixture.create({ notes: 'foo' }))
91
+ expect(badge.notes).toEqual('foo')
92
+ })
93
+
94
+ test('should be optional', () => {
95
+ const badge = new Badge(badgeDataFixture.omit('notes').create())
96
+ expect(badge.notes).toBeUndefined()
97
+ })
98
+ })
99
+
100
+ describe('links', () => {
101
+ test('should be set from the data', () => {
102
+ const badge = new Badge(badgeDataFixture.create({ links: [{ title: 'foo', href: 'bar' }] }))
103
+ expect(badge.links).toStrictEqual([{ title: 'foo', href: 'bar' }])
104
+ })
105
+
106
+ test('should be optional', () => {
107
+ const badge = new Badge(badgeDataFixture.omit('links').create())
108
+ expect(badge.links).toHaveLength(0)
109
+ })
110
+ })
111
+
112
+ describe('effect', () => {
113
+ test('should be set from the data', () => {
114
+ const badge = new Badge(badgeDataFixture.create({ effect: 'foo' }))
115
+ expect(badge.effect).toEqual('foo')
116
+ })
117
+
118
+ test('should be optional', () => {
119
+ const badge = new Badge(badgeDataFixture.omit('effect').create())
120
+ expect(badge.effect).toBeUndefined()
121
+ })
122
+ })
123
+
124
+ describe('setTitle', () => {
125
+ test('should be set from the data', () => {
126
+ const badge = new Badge(badgeDataFixture.create({ setTitleId: [123, 456] }))
127
+ expect(badge.setTitleId).toStrictEqual([123, 456])
128
+ })
129
+
130
+ test('should treat the praetorian id as optional', () => {
131
+ const badge = new Badge(badgeDataFixture.create({ setTitleId: [123] }))
132
+ expect(badge.setTitleId).toStrictEqual([123])
133
+ })
134
+
135
+ test('should be optional', () => {
136
+ const badge = new Badge(badgeDataFixture.omit('setTitleId').create())
137
+ expect(badge.setTitleId).toBeUndefined()
138
+ })
139
+ })
140
+
141
+ describe('ignoreInTotals', () => {
142
+ test('should be set from the data', () => {
143
+ const badge = new Badge(badgeDataFixture.create({ ignoreInTotals: true }))
144
+ expect(badge.ignoreInTotals).toEqual(true)
145
+ })
146
+
147
+ test('should default to false', () => {
148
+ const badge = new Badge(badgeDataFixture.omit('ignoreInTotals').create())
149
+ expect(badge.ignoreInTotals).toEqual(false)
150
+ })
151
+ })
152
+
153
+ describe('requirements', () => {
154
+ test(`should throw an error on duplicate key`, () => {
155
+ const data = badgeDataFixture.create({
156
+ key: 'badge',
157
+ requirements: [
158
+ badgeRequirementDataFixture.create({ key: 'foo' }),
159
+ badgeRequirementDataFixture.create({ key: 'foo' }),
160
+ ],
161
+ })
162
+ expect(() => new Badge(data)).toThrow('Duplicate badge requirement key [badge:foo]')
163
+ })
164
+ })
165
+
166
+ describe('getRequirement', () => {
167
+ test(`should retrieve requirement from the index`, () => {
168
+ const data = badgeDataFixture.create({
169
+ requirements: [badgeRequirementDataFixture.create({ key: 'foo' })],
170
+ })
171
+
172
+ expect(new Badge(data).getRequirement('foo')).not.toBeUndefined()
173
+ })
174
+
175
+ test(`should throw error for unknown requirement`, () => {
176
+ const data = badgeDataFixture.create({
177
+ requirements: [],
178
+ })
179
+
180
+ expect(() => new Badge(data).getRequirement('foo')).toThrow('Unknown badge requirement key [foo]')
181
+ })
182
+ })
183
+
184
+ describe('zoneKeys', () => {
185
+ test(`should return the list of keys`, () => {
186
+ const badge = new Badge(badgeDataFixture.create({
187
+ requirements: [
188
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
189
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
190
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'b' } }),
191
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
192
+ ],
193
+ }))
194
+ expect(badge.zoneKeys).toStrictEqual(['a', 'c', 'b'])
195
+ })
196
+
197
+ test(`should return undefined if there no zones`, () => {
198
+ const badge = new Badge(badgeDataFixture.create({
199
+ requirements: [
200
+ badgeRequirementDataFixture.omit('location').create(),
201
+ ],
202
+ }))
203
+ expect(badge.zoneKey).toBeUndefined()
204
+ })
205
+
206
+ test(`should ignore requirements with no location`, () => {
207
+ const badge = new Badge(badgeDataFixture.create({
208
+ requirements: [
209
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
210
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
211
+ badgeRequirementDataFixture.omit('location').create(),
212
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
213
+ ],
214
+ }))
215
+ expect(badge.zoneKeys).toStrictEqual(['a', 'c'])
216
+ })
217
+ })
218
+
219
+ describe('zoneKey', () => {
220
+ test(`should return the key for a single zone`, () => {
221
+ const badge = new Badge(badgeDataFixture.create({
222
+ requirements: [
223
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
224
+ ],
225
+ }))
226
+ expect(badge.zoneKey).toBe('a')
227
+ })
228
+
229
+ test(`should return undefined if there no zones`, () => {
230
+ const badge = new Badge(badgeDataFixture.create({
231
+ requirements: [
232
+ badgeRequirementDataFixture.omit('location').create(),
233
+ ],
234
+ }))
235
+ expect(badge.zoneKey).toBeUndefined()
236
+ })
237
+
238
+ test(`should return undefined if there are multiple zones`, () => {
239
+ const badge = new Badge(badgeDataFixture.create({
240
+ requirements: [
241
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
242
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
243
+ ],
244
+ }))
245
+ expect(badge.zoneKey).toBeUndefined()
246
+ })
247
+ })
248
+
249
+ describe(compareByDefaultName.name, () => {
250
+ test(`should compare two badges by name`, () => {
251
+ const badgeA = new Badge(badgeDataFixture.create({ name: 'A' }))
252
+ const badgeB = new Badge(badgeDataFixture.create({ name: 'B' }))
253
+ expect(compareByDefaultName(badgeA, badgeB)).toBeLessThan(0)
254
+ expect([badgeB, badgeA].sort(compareByDefaultName)).toStrictEqual([badgeA, badgeB])
255
+ })
256
+
257
+ test(`should return 0 for equal names`, () => {
258
+ const badgeA = new Badge(badgeDataFixture.create({ name: 'A' }))
259
+ const badgeB = new Badge(badgeDataFixture.create({ name: 'A' }))
260
+ expect(compareByDefaultName(badgeA, badgeB)).toEqual(0)
261
+ })
262
+
263
+ test(`should compare two undefined values`, () => {
264
+ const badgeA = new Badge(badgeDataFixture.create({ name: [] }))
265
+ const badgeB = new Badge(badgeDataFixture.create({ name: [] }))
266
+ expect(compareByDefaultName(badgeA, badgeB)).toEqual(0)
267
+ })
268
+
269
+ test(`should sort undefined values last`, () => {
270
+ const badgeA = new Badge(badgeDataFixture.create({ name: 'A' }))
271
+ const badgeB = new Badge(badgeDataFixture.create({ name: [] }))
272
+ expect([badgeA, badgeB].sort(compareByDefaultName)).toStrictEqual([badgeA, badgeB])
273
+ expect([badgeB, badgeA].sort(compareByDefaultName)).toStrictEqual([badgeA, badgeB])
274
+ })
275
+ })
276
+
277
+ describe(compareByZoneKey.name, () => {
278
+ test(`should compare two badges by zoneKey`, () => {
279
+ const badgeA = new Badge(badgeDataFixture.create({
280
+ requirements: [
281
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
282
+ ],
283
+ }))
284
+ const badgeB = new Badge(badgeDataFixture.create({
285
+ requirements: [
286
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'b' } }),
287
+ ],
288
+ }))
289
+ expect(compareByZoneKey(badgeA, badgeB)).toBeLessThan(0)
290
+ expect([badgeB, badgeA].sort(compareByZoneKey)).toStrictEqual([badgeA, badgeB])
291
+ })
292
+
293
+ test(`should return 0 for equal zoneKeys`, () => {
294
+ const badgeA = new Badge(badgeDataFixture.create({
295
+ requirements: [
296
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
297
+ ],
298
+ }))
299
+ const badgeB = new Badge(badgeDataFixture.create({
300
+ requirements: [
301
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
302
+ ],
303
+ }))
304
+ expect(compareByZoneKey(badgeA, badgeB)).toEqual(0)
305
+ })
306
+
307
+ test(`should equate two undefined values`, () => {
308
+ const badgeA = new Badge(badgeDataFixture.create({
309
+ requirements: [
310
+ badgeRequirementDataFixture.omit('location').create(),
311
+ ],
312
+ }))
313
+ const badgeB = new Badge(badgeDataFixture.create({
314
+ requirements: [
315
+ badgeRequirementDataFixture.omit('location').create(),
316
+ ],
317
+ }))
318
+ expect(compareByZoneKey(badgeA, badgeB)).toEqual(0)
319
+ })
320
+
321
+ test(`should sort badges with multiple values last`, () => {
322
+ const badgeA = new Badge(badgeDataFixture.create({
323
+ requirements: [
324
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
325
+ ],
326
+ }))
327
+ const badgeB = new Badge(badgeDataFixture.create({
328
+ requirements: [
329
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'b' } }),
330
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
331
+ ],
332
+ }))
333
+ expect([badgeA, badgeB].sort(compareByZoneKey)).toStrictEqual([badgeA, badgeB])
334
+ expect([badgeB, badgeA].sort(compareByZoneKey)).toStrictEqual([badgeA, badgeB])
335
+ })
336
+ })
337
+ })
@@ -0,0 +1,76 @@
1
+ import { BundleHeader } from '../../main'
2
+ import { bundleHeaderDataFixture } from '../api/bundle-header-data.fixture'
3
+
4
+ describe(BundleHeader.name, () => {
5
+ describe('name', () => {
6
+ test(`should be set from the data`, () => {
7
+ const header = new BundleHeader(bundleHeaderDataFixture.create({ name: 'foo' }))
8
+ expect(header.name).toEqual('foo')
9
+ })
10
+
11
+ test(`should be optional`, () => {
12
+ const header = new BundleHeader(bundleHeaderDataFixture.omit('name').create())
13
+ expect(header.name).toBeUndefined()
14
+ })
15
+ })
16
+
17
+ describe('description', () => {
18
+ test(`should be set from the data`, () => {
19
+ const header = new BundleHeader(bundleHeaderDataFixture.create({ description: 'foo' }))
20
+ expect(header.description).toEqual('foo')
21
+ })
22
+
23
+ test(`should be optional`, () => {
24
+ const header = new BundleHeader(bundleHeaderDataFixture.omit('description').create())
25
+ expect(header.description).toBeUndefined()
26
+ })
27
+ })
28
+
29
+ describe('repositoryUrl', () => {
30
+ test(`should be set from the data`, () => {
31
+ const header = new BundleHeader(bundleHeaderDataFixture.create({ repositoryUrl: 'foo' }))
32
+ expect(header.repositoryUrl).toEqual('foo')
33
+ })
34
+
35
+ test(`should be optional`, () => {
36
+ const header = new BundleHeader(bundleHeaderDataFixture.omit('repositoryUrl').create())
37
+ expect(header.repositoryUrl).toBeUndefined()
38
+ })
39
+ })
40
+
41
+ describe('changelogUrl', () => {
42
+ test(`should be set from the data`, () => {
43
+ const header = new BundleHeader(bundleHeaderDataFixture.create({ changelogUrl: 'foo' }))
44
+ expect(header.changelogUrl).toEqual('foo')
45
+ })
46
+
47
+ test(`should be optional`, () => {
48
+ const header = new BundleHeader(bundleHeaderDataFixture.omit('changelogUrl').create())
49
+ expect(header.changelogUrl).toBeUndefined()
50
+ })
51
+ })
52
+
53
+ describe('links', () => {
54
+ test(`should be set from the data`, () => {
55
+ const header = new BundleHeader(bundleHeaderDataFixture.create({ links: [{ title: 'foo', href: 'bar' }] }))
56
+ expect(header.links).toStrictEqual([{ title: 'foo', href: 'bar' }])
57
+ })
58
+
59
+ test(`should be optional`, () => {
60
+ const header = new BundleHeader(bundleHeaderDataFixture.omit('links').create())
61
+ expect(header.links).toHaveLength(0)
62
+ })
63
+ })
64
+
65
+ describe('version', () => {
66
+ test(`should be set from the data`, () => {
67
+ const header = new BundleHeader(bundleHeaderDataFixture.create({ version: 'foo' }))
68
+ expect(header.version).toEqual('foo')
69
+ })
70
+
71
+ test(`should be optional`, () => {
72
+ const header = new BundleHeader(bundleHeaderDataFixture.omit('version').create())
73
+ expect(header.version).toBeUndefined()
74
+ })
75
+ })
76
+ })
@@ -0,0 +1,282 @@
1
+ import { CohContentDatabase } from '../../main'
2
+ import { archetypeDataFixture } from '../api/archetype-data.fixture'
3
+ import { badgeDataFixture } from '../api/badge-data.fixture'
4
+ import { zoneDataFixture } from '../api/zone-data.fixture'
5
+ import { contactDataFixture } from '../api/contact-data.fixture'
6
+ import { missionDataFixture } from '../api/mission-data.fixture'
7
+ import { bundleDataFixture } from '../api/bundle-data.fixture'
8
+
9
+ describe(CohContentDatabase.name, () => {
10
+ describe('Constructor', () => {
11
+ test('should load a basic bundle', () => {
12
+ new CohContentDatabase(bundleDataFixture.create())
13
+ })
14
+ })
15
+
16
+ describe('header', () => {
17
+ test(`should accept an undefined field`, () => {
18
+ const database = new CohContentDatabase(
19
+ bundleDataFixture.omit('header').create(),
20
+ )
21
+ expect(database.header).toBeDefined()
22
+ expect(database.header?.name).toBeUndefined()
23
+ })
24
+
25
+ test(`should load values from bundle`, () => {
26
+ const database = new CohContentDatabase(
27
+ bundleDataFixture.create(
28
+ { header: { name: 'Homecoming' } },
29
+ ),
30
+ )
31
+
32
+ expect(database.header?.name).toBe('Homecoming')
33
+ })
34
+ })
35
+
36
+ describe('servers', () => {
37
+ test(`should accept an undefined field`, () => {
38
+ const database = new CohContentDatabase(
39
+ bundleDataFixture.omit('servers').create(),
40
+ )
41
+ expect(database.servers).toHaveLength(0)
42
+ })
43
+
44
+ test(`should load values from bundle`, () => {
45
+ const database = new CohContentDatabase(
46
+ bundleDataFixture
47
+ .create({ servers: ['Foo', 'Bar'] }),
48
+ )
49
+ expect(database.servers).toStrictEqual(['Foo', 'Bar'])
50
+ })
51
+ })
52
+
53
+ describe('archetypes', () => {
54
+ test(`should accept an undefined field`, () => {
55
+ const database = new CohContentDatabase(bundleDataFixture
56
+ .omit('archetypes')
57
+ .create())
58
+ expect(database.archetypes).toHaveLength(0)
59
+ })
60
+
61
+ test(`should load data from bundle`, () => {
62
+ const database = new CohContentDatabase(
63
+ bundleDataFixture
64
+ .create({ archetypes: [archetypeDataFixture.create({ key: 'foo' })] }),
65
+ )
66
+ expect(database.getArchetype('foo')).not.toBeUndefined()
67
+ })
68
+ })
69
+
70
+ describe('badges', () => {
71
+ test(`should accept an undefined field`, () => {
72
+ const database = new CohContentDatabase(
73
+ bundleDataFixture.omit('badges').create(),
74
+ )
75
+ expect(database.badges).toHaveLength(0)
76
+ })
77
+
78
+ test(`should load data from bundle`, () => {
79
+ const database = new CohContentDatabase(
80
+ bundleDataFixture
81
+ .create({ badges: [badgeDataFixture.create({ key: 'foo' })] }),
82
+ )
83
+ expect(database.getBadge('foo')).not.toBeUndefined()
84
+ })
85
+ })
86
+
87
+ describe('zones', () => {
88
+ test(`should accept an undefined field`, () => {
89
+ const database = new CohContentDatabase(
90
+ bundleDataFixture.omit('zones').create(),
91
+ )
92
+ expect(database.zones).toHaveLength(0)
93
+ })
94
+
95
+ test(`should load data from bundle`, () => {
96
+ const database = new CohContentDatabase(
97
+ bundleDataFixture
98
+ .create({ zones: [zoneDataFixture.create({ key: 'foo' })] }),
99
+ )
100
+ expect(database.getZone('foo')).not.toBeUndefined()
101
+ })
102
+ })
103
+
104
+ describe('contacts', () => {
105
+ test(`should accept an undefined field`, () => {
106
+ const database = new CohContentDatabase(
107
+ bundleDataFixture.omit('contacts').create(),
108
+ )
109
+ expect(database.contacts).toHaveLength(0)
110
+ })
111
+
112
+ test(`should load data from bundle`, () => {
113
+ const database = new CohContentDatabase(
114
+ bundleDataFixture
115
+ .create({ contacts: [contactDataFixture.create({ key: 'foo' })] }),
116
+ )
117
+ expect(database.getContact('foo')).not.toBeUndefined()
118
+ })
119
+ })
120
+
121
+ describe('missions', () => {
122
+ test(`should accept an undefined field`, () => {
123
+ const database = new CohContentDatabase(
124
+ bundleDataFixture.omit('missions').create(),
125
+ )
126
+ expect(database.missions).toHaveLength(0)
127
+ })
128
+
129
+ test(`should load data from bundle`, () => {
130
+ const database = new CohContentDatabase(
131
+ bundleDataFixture
132
+ .create({ missions: [missionDataFixture.create({ key: 'foo' })] }),
133
+ )
134
+ expect(database.getMission('foo')).not.toBeUndefined()
135
+ })
136
+ })
137
+
138
+ describe('getArchetype', () => {
139
+ test(`should retrieve archetype from the index`, () => {
140
+ const database = new CohContentDatabase(
141
+ bundleDataFixture.create({
142
+ archetypes: [archetypeDataFixture.create({ key: 'foo' })],
143
+ }),
144
+ )
145
+ expect(database.getArchetype('foo')).not.toBeUndefined()
146
+ })
147
+
148
+ test(`should return undefined for unknown archetype`, () => {
149
+ const database = new CohContentDatabase(
150
+ bundleDataFixture.create({ archetypes: [] }),
151
+ )
152
+ expect(database.getArchetype('foo')).toBeUndefined()
153
+ })
154
+
155
+ test(`should return undefined for undefined key`, () => {
156
+ const database = new CohContentDatabase(
157
+ bundleDataFixture.create({ archetypes: [] }),
158
+ )
159
+ const key = undefined
160
+ expect(database.getArchetype(key)).toBeUndefined()
161
+ })
162
+ })
163
+
164
+ describe('getZone', () => {
165
+ test(`should retrieve zone from the index`, () => {
166
+ const database = new CohContentDatabase(
167
+ bundleDataFixture.create({
168
+ zones: [zoneDataFixture.create({ key: 'foo' })],
169
+ }),
170
+ )
171
+ expect(database.getZone('foo')).not.toBeUndefined()
172
+ })
173
+
174
+ test(`should return undefined for unknown zone`, () => {
175
+ const database = new CohContentDatabase(bundleDataFixture.create({ zones: [] }))
176
+ expect(database.getZone('foo')).toBeUndefined()
177
+ })
178
+
179
+ test(`should return undefined for undefined key`, () => {
180
+ const database = new CohContentDatabase(
181
+ bundleDataFixture.create({ zones: [] }),
182
+ )
183
+ const key = undefined
184
+ expect(database.getZone(key)).toBeUndefined()
185
+ })
186
+ })
187
+
188
+ describe('getContact', () => {
189
+ test(`should retrieve contact from the index`, () => {
190
+ const database = new CohContentDatabase(
191
+ bundleDataFixture.create({
192
+ contacts: [contactDataFixture.create({ key: 'foo' })],
193
+ }),
194
+ )
195
+ expect(database.getContact('foo')).not.toBeUndefined()
196
+ })
197
+
198
+ test(`should return undefined for unknown contact`, () => {
199
+ const database = new CohContentDatabase(
200
+ bundleDataFixture.create({ contacts: [] }),
201
+ )
202
+ expect(database.getContact('foo')).toBeUndefined()
203
+ })
204
+
205
+ test(`should return undefined for undefined key`, () => {
206
+ const database = new CohContentDatabase(
207
+ bundleDataFixture.create({ contacts: [] }),
208
+ )
209
+ const key = undefined
210
+ expect(database.getContact(key)).toBeUndefined()
211
+ })
212
+ })
213
+
214
+ describe('getMission', () => {
215
+ test(`should retrieve mission from the index`, () => {
216
+ const database = new CohContentDatabase(
217
+ bundleDataFixture.create({
218
+ missions: [missionDataFixture.create({ key: 'foo' })],
219
+ }),
220
+ )
221
+ expect(database.getMission('foo')).not.toBeUndefined()
222
+ })
223
+
224
+ test(`should return undefined for unknown mission`, () => {
225
+ const database = new CohContentDatabase(
226
+ bundleDataFixture.create({ missions: [] }),
227
+ )
228
+ expect(database.getMission('foo')).toBeUndefined()
229
+ })
230
+
231
+ test(`should return undefined for undefined key`, () => {
232
+ const database = new CohContentDatabase(
233
+ bundleDataFixture.create({ missions: [] }),
234
+ )
235
+ const key = undefined
236
+ expect(database.getMission(key)).toBeUndefined()
237
+ })
238
+ })
239
+
240
+ describe('getBadge', () => {
241
+ test(`should retrieve badge from the index`, () => {
242
+ const database = new CohContentDatabase(
243
+ bundleDataFixture.create({
244
+ badges: [badgeDataFixture.create({ key: 'foo' })],
245
+ }),
246
+ )
247
+ expect(database.getBadge('foo')).not.toBeUndefined()
248
+ })
249
+
250
+ test(`should return undefined for unknown badge`, () => {
251
+ const database = new CohContentDatabase(
252
+ bundleDataFixture.create({ badges: [] }),
253
+ )
254
+ expect(database.getBadge('foo')).toBeUndefined()
255
+ })
256
+
257
+ test(`should return undefined for undefined key`, () => {
258
+ const database = new CohContentDatabase(
259
+ bundleDataFixture.create({ badges: [] }),
260
+ )
261
+ const key = undefined
262
+ expect(database.getBadge(key)).toBeUndefined()
263
+ })
264
+ })
265
+
266
+ describe('searchBadges', () => {
267
+ test(`should search the badge list`, () => {
268
+ const database = new CohContentDatabase(
269
+ bundleDataFixture.create({
270
+ badges: [
271
+ badgeDataFixture.create({ key: 'foo', name: [{ value: 'Foo' }] }),
272
+ badgeDataFixture.create({ key: 'bar', name: [{ value: 'Bar' }] }),
273
+ ],
274
+ }),
275
+ )
276
+
277
+ const result = database.searchBadges({ query: { str: 'oo' } })
278
+ expect(result.totalItems).toBe(1)
279
+ expect(result.items.map(x => x.key)).toStrictEqual(['foo'])
280
+ })
281
+ })
282
+ })