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,6 +1,6 @@
|
|
|
1
|
-
import { Badge } from '../../main'
|
|
1
|
+
import { Badge, compareByDefaultName, compareByZoneKey } from '../../main'
|
|
2
2
|
import { badgeDataFixture } from '../api/badge-data.fixture'
|
|
3
|
-
import {
|
|
3
|
+
import { badgeRequirementDataFixture } from '../api/badge-requirement-data.fixture'
|
|
4
4
|
|
|
5
5
|
describe(Badge.name, () => {
|
|
6
6
|
describe('Constructor', () => {
|
|
@@ -9,33 +9,329 @@ describe(Badge.name, () => {
|
|
|
9
9
|
})
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
describe('
|
|
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', () => {
|
|
13
154
|
test(`should throw an error on duplicate key`, () => {
|
|
14
155
|
const data = badgeDataFixture.create({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
156
|
+
key: 'badge',
|
|
157
|
+
requirements: [
|
|
158
|
+
badgeRequirementDataFixture.create({ key: 'foo' }),
|
|
159
|
+
badgeRequirementDataFixture.create({ key: 'foo' }),
|
|
18
160
|
],
|
|
19
161
|
})
|
|
20
|
-
expect(() => new Badge(data)).toThrow('Duplicate badge
|
|
162
|
+
expect(() => new Badge(data)).toThrow('Duplicate badge requirement key [badge:foo]')
|
|
21
163
|
})
|
|
22
164
|
})
|
|
23
165
|
|
|
24
|
-
describe('
|
|
25
|
-
test(`should retrieve
|
|
166
|
+
describe('getRequirement', () => {
|
|
167
|
+
test(`should retrieve requirement from the index`, () => {
|
|
26
168
|
const data = badgeDataFixture.create({
|
|
27
|
-
|
|
169
|
+
requirements: [badgeRequirementDataFixture.create({ key: 'foo' })],
|
|
28
170
|
})
|
|
29
171
|
|
|
30
|
-
expect(new Badge(data).
|
|
172
|
+
expect(new Badge(data).getRequirement('foo')).not.toBeUndefined()
|
|
31
173
|
})
|
|
32
174
|
|
|
33
|
-
test(`should throw error for unknown
|
|
175
|
+
test(`should throw error for unknown requirement`, () => {
|
|
34
176
|
const data = badgeDataFixture.create({
|
|
35
|
-
|
|
177
|
+
requirements: [],
|
|
36
178
|
})
|
|
37
179
|
|
|
38
|
-
expect(() => new Badge(data).
|
|
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])
|
|
39
335
|
})
|
|
40
336
|
})
|
|
41
337
|
})
|
|
@@ -2,7 +2,9 @@ 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 {
|
|
5
|
+
import { zoneDataFixture } from '../api/zone-data.fixture'
|
|
6
|
+
import { contactDataFixture } from '../api/contact-data.fixture'
|
|
7
|
+
import { missionDataFixture } from '../api/mission-data.fixture'
|
|
6
8
|
|
|
7
9
|
describe(CohContentDatabase.name, () => {
|
|
8
10
|
test('should load a basic bundle', () => {
|
|
@@ -14,7 +16,7 @@ describe(CohContentDatabase.name, () => {
|
|
|
14
16
|
const data = contentBundleFixture
|
|
15
17
|
.omit('servers')
|
|
16
18
|
.create()
|
|
17
|
-
expect(
|
|
19
|
+
expect(new CohContentDatabase(data).servers).toHaveLength(0)
|
|
18
20
|
})
|
|
19
21
|
|
|
20
22
|
test(`should load values from bundle`, () => {
|
|
@@ -32,20 +34,20 @@ describe(CohContentDatabase.name, () => {
|
|
|
32
34
|
archetypeDataFixture.create({ key: 'foo' }),
|
|
33
35
|
],
|
|
34
36
|
})
|
|
35
|
-
expect(() => new CohContentDatabase(data)).toThrow(
|
|
37
|
+
expect(() => new CohContentDatabase(data)).toThrow(`Duplicate archetype key 'foo'`)
|
|
36
38
|
})
|
|
37
39
|
|
|
38
40
|
test(`should accept an undefined field`, () => {
|
|
39
41
|
const data = contentBundleFixture
|
|
40
42
|
.omit('archetypes')
|
|
41
43
|
.create()
|
|
42
|
-
expect(
|
|
44
|
+
expect(new CohContentDatabase(data).archetypes).toHaveLength(0)
|
|
43
45
|
})
|
|
44
46
|
|
|
45
47
|
test(`should load data from bundle`, () => {
|
|
46
48
|
const data = contentBundleFixture
|
|
47
49
|
.create({ archetypes: [archetypeDataFixture.create({ key: 'foo' })] })
|
|
48
|
-
expect(
|
|
50
|
+
expect(new CohContentDatabase(data).getArchetype('foo')).not.toBeUndefined()
|
|
49
51
|
})
|
|
50
52
|
})
|
|
51
53
|
|
|
@@ -64,26 +66,64 @@ describe(CohContentDatabase.name, () => {
|
|
|
64
66
|
const data = contentBundleFixture
|
|
65
67
|
.omit('badges')
|
|
66
68
|
.create()
|
|
67
|
-
expect(
|
|
69
|
+
expect(new CohContentDatabase(data).badges).toHaveLength(0)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('zones', () => {
|
|
74
|
+
test(`should throw an error on duplicate zone`, () => {
|
|
75
|
+
const data = contentBundleFixture.create({
|
|
76
|
+
zones: [
|
|
77
|
+
zoneDataFixture.create({ key: 'foo' }),
|
|
78
|
+
zoneDataFixture.create({ key: 'foo' }),
|
|
79
|
+
],
|
|
80
|
+
})
|
|
81
|
+
expect(() => new CohContentDatabase(data)).toThrow(`Duplicate zone key 'foo'`)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test(`should accept an undefined field`, () => {
|
|
85
|
+
const data = contentBundleFixture
|
|
86
|
+
.omit('zones')
|
|
87
|
+
.create()
|
|
88
|
+
expect(new CohContentDatabase(data).zones).toHaveLength(0)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('contacts', () => {
|
|
93
|
+
test(`should throw an error on duplicate contact`, () => {
|
|
94
|
+
const data = contentBundleFixture.create({
|
|
95
|
+
contacts: [
|
|
96
|
+
contactDataFixture.create({ key: 'foo' }),
|
|
97
|
+
contactDataFixture.create({ key: 'foo' }),
|
|
98
|
+
],
|
|
99
|
+
})
|
|
100
|
+
expect(() => new CohContentDatabase(data)).toThrow(`Duplicate contact key 'foo'`)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test(`should accept an undefined field`, () => {
|
|
104
|
+
const data = contentBundleFixture
|
|
105
|
+
.omit('contacts')
|
|
106
|
+
.create()
|
|
107
|
+
expect(new CohContentDatabase(data).contacts).toHaveLength(0)
|
|
68
108
|
})
|
|
69
109
|
})
|
|
70
110
|
|
|
71
|
-
describe('
|
|
72
|
-
test(`should throw an error on duplicate
|
|
111
|
+
describe('missions', () => {
|
|
112
|
+
test(`should throw an error on duplicate mission`, () => {
|
|
73
113
|
const data = contentBundleFixture.create({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
114
|
+
missions: [
|
|
115
|
+
missionDataFixture.create({ key: 'foo' }),
|
|
116
|
+
missionDataFixture.create({ key: 'foo' }),
|
|
77
117
|
],
|
|
78
118
|
})
|
|
79
|
-
expect(() => new CohContentDatabase(data)).toThrow(
|
|
119
|
+
expect(() => new CohContentDatabase(data)).toThrow(`Duplicate mission key 'foo'`)
|
|
80
120
|
})
|
|
81
121
|
|
|
82
122
|
test(`should accept an undefined field`, () => {
|
|
83
123
|
const data = contentBundleFixture
|
|
84
|
-
.omit('
|
|
124
|
+
.omit('missions')
|
|
85
125
|
.create()
|
|
86
|
-
expect(
|
|
126
|
+
expect(new CohContentDatabase(data).missions).toHaveLength(0)
|
|
87
127
|
})
|
|
88
128
|
})
|
|
89
129
|
|
|
@@ -96,30 +136,70 @@ describe(CohContentDatabase.name, () => {
|
|
|
96
136
|
expect(new CohContentDatabase(data).getArchetype('foo')).not.toBeUndefined()
|
|
97
137
|
})
|
|
98
138
|
|
|
99
|
-
test(`should
|
|
139
|
+
test(`should return undefined for unknown archetype`, () => {
|
|
140
|
+
const data = contentBundleFixture.create({ archetypes: [] })
|
|
141
|
+
expect(new CohContentDatabase(data).getArchetype('foo')).toBeUndefined()
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test(`should return undefined for undefined key`, () => {
|
|
145
|
+
expect(new CohContentDatabase(contentBundleFixture.create({ archetypes: [] })).getArchetype()).toBeUndefined()
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('getZone', () => {
|
|
150
|
+
test(`should retrieve zone from the index`, () => {
|
|
100
151
|
const data = contentBundleFixture.create({
|
|
101
|
-
|
|
152
|
+
zones: [zoneDataFixture.create({ key: 'foo' })],
|
|
102
153
|
})
|
|
103
154
|
|
|
104
|
-
expect(
|
|
155
|
+
expect(new CohContentDatabase(data).getZone('foo')).not.toBeUndefined()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test(`should return undefined for unknown zone`, () => {
|
|
159
|
+
const data = contentBundleFixture.create({ zones: [] })
|
|
160
|
+
expect(new CohContentDatabase(data).getZone('foo')).toBeUndefined()
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
test(`should return undefined for undefined key`, () => {
|
|
164
|
+
expect(new CohContentDatabase(contentBundleFixture.create({ zones: [] })).getZone()).toBeUndefined()
|
|
105
165
|
})
|
|
106
166
|
})
|
|
107
167
|
|
|
108
|
-
describe('
|
|
109
|
-
test(`should retrieve
|
|
168
|
+
describe('getContact', () => {
|
|
169
|
+
test(`should retrieve contact from the index`, () => {
|
|
110
170
|
const data = contentBundleFixture.create({
|
|
111
|
-
|
|
171
|
+
contacts: [contactDataFixture.create({ key: 'foo' })],
|
|
112
172
|
})
|
|
113
173
|
|
|
114
|
-
expect(new CohContentDatabase(data).
|
|
174
|
+
expect(new CohContentDatabase(data).getContact('foo')).not.toBeUndefined()
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test(`should return undefined for unknown contact`, () => {
|
|
178
|
+
const data = contentBundleFixture.create({ contacts: [] })
|
|
179
|
+
expect(new CohContentDatabase(data).getContact('foo')).toBeUndefined()
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test(`should return undefined for undefined key`, () => {
|
|
183
|
+
expect(new CohContentDatabase(contentBundleFixture.create({ contacts: [] })).getContact()).toBeUndefined()
|
|
115
184
|
})
|
|
185
|
+
})
|
|
116
186
|
|
|
117
|
-
|
|
187
|
+
describe('getMission', () => {
|
|
188
|
+
test(`should retrieve mission from the index`, () => {
|
|
118
189
|
const data = contentBundleFixture.create({
|
|
119
|
-
|
|
190
|
+
missions: [missionDataFixture.create({ key: 'foo' })],
|
|
120
191
|
})
|
|
121
192
|
|
|
122
|
-
expect(
|
|
193
|
+
expect(new CohContentDatabase(data).getMission('foo')).not.toBeUndefined()
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test(`should return undefined for unknown mission`, () => {
|
|
197
|
+
const data = contentBundleFixture.create({ missions: [] })
|
|
198
|
+
expect(new CohContentDatabase(data).getMission('foo')).toBeUndefined()
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test(`should return undefined for undefined key`, () => {
|
|
202
|
+
expect(new CohContentDatabase(contentBundleFixture.create({ missions: [] })).getMission()).toBeUndefined()
|
|
123
203
|
})
|
|
124
204
|
})
|
|
125
205
|
|
|
@@ -132,12 +212,13 @@ describe(CohContentDatabase.name, () => {
|
|
|
132
212
|
expect(new CohContentDatabase(data).getBadge('foo')).not.toBeUndefined()
|
|
133
213
|
})
|
|
134
214
|
|
|
135
|
-
test(`should
|
|
136
|
-
const data = contentBundleFixture.create({
|
|
137
|
-
|
|
138
|
-
|
|
215
|
+
test(`should return undefined for unknown badge`, () => {
|
|
216
|
+
const data = contentBundleFixture.create({ badges: [] })
|
|
217
|
+
expect(new CohContentDatabase(data).getBadge('foo')).toBeUndefined()
|
|
218
|
+
})
|
|
139
219
|
|
|
140
|
-
|
|
220
|
+
test(`should return undefined for undefined key`, () => {
|
|
221
|
+
expect(new CohContentDatabase(contentBundleFixture.create({ badges: [] })).getBadge()).toBeUndefined()
|
|
141
222
|
})
|
|
142
223
|
})
|
|
143
224
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Contact } from '../../main'
|
|
2
|
+
import { contactDataFixture } from '../api/contact-data.fixture'
|
|
3
|
+
|
|
4
|
+
describe(Contact.name, () => {
|
|
5
|
+
describe('Constructor', () => {
|
|
6
|
+
test(`should accept the test fixture`, () => {
|
|
7
|
+
new Contact(contactDataFixture.create())
|
|
8
|
+
})
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
describe('key', () => {
|
|
12
|
+
test(`should be set from the data`, () => {
|
|
13
|
+
const contact = new Contact(contactDataFixture.create({ key: 'foo' }))
|
|
14
|
+
expect(contact.key).toEqual('foo')
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('name', () => {
|
|
19
|
+
test(`should be set from the data`, () => {
|
|
20
|
+
const contact = new Contact(contactDataFixture.create({ name: 'foo' }))
|
|
21
|
+
expect(contact.name).toEqual('foo')
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('title', () => {
|
|
26
|
+
test(`should be set from the data`, () => {
|
|
27
|
+
const contact = new Contact(contactDataFixture.create({ title: 'foo' }))
|
|
28
|
+
expect(contact.title).toEqual('foo')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test(`should be optional`, () => {
|
|
32
|
+
const contact = new Contact(contactDataFixture.omit('title').create())
|
|
33
|
+
expect(contact.title).toBeUndefined()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('morality', () => {
|
|
38
|
+
test(`should be set from the data`, () => {
|
|
39
|
+
const contact = new Contact(contactDataFixture.create({ morality: ['hero'] }))
|
|
40
|
+
expect(contact.morality?.hero).toBeTruthy()
|
|
41
|
+
expect(contact.morality?.vigilante).toBeFalsy()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test(`should be optional`, () => {
|
|
45
|
+
const contact = new Contact(contactDataFixture.omit('morality').create())
|
|
46
|
+
expect(contact.morality?.all).toBeTruthy()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe('zoneKey', () => {
|
|
51
|
+
test(`should be set from the data`, () => {
|
|
52
|
+
const contact = new Contact(contactDataFixture.create({ location: { zoneKey: 'atlas-park', coords: [1, -2, 3.5] } }))
|
|
53
|
+
expect(contact.location).toEqual({ zoneKey: 'atlas-park', coords: [1, -2, 3.5] })
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test(`should be optional`, () => {
|
|
57
|
+
const contact = new Contact(contactDataFixture.omit('location').create())
|
|
58
|
+
expect(contact.location).toBeUndefined()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('levelRange', () => {
|
|
63
|
+
test(`should be set from the data`, () => {
|
|
64
|
+
const contact = new Contact(contactDataFixture.create({ levelRange: [1, 2] }))
|
|
65
|
+
expect(contact.levelRange).toStrictEqual([1, 2])
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test(`should be optional`, () => {
|
|
69
|
+
const contact = new Contact(contactDataFixture.omit('levelRange').create())
|
|
70
|
+
expect(contact.levelRange).toBeUndefined()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('notes', () => {
|
|
75
|
+
test(`should be set from the data`, () => {
|
|
76
|
+
const contact = new Contact(contactDataFixture.create({ notes: 'foo' }))
|
|
77
|
+
expect(contact.notes).toEqual('foo')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test(`should be optional`, () => {
|
|
81
|
+
const contact = new Contact(contactDataFixture.omit('notes').create())
|
|
82
|
+
expect(contact.notes).toBeUndefined()
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('links', () => {
|
|
87
|
+
test(`should be set from the data`, () => {
|
|
88
|
+
const contact = new Contact(contactDataFixture.create({ links: [{ title: 'foo', href: 'bar' }] }))
|
|
89
|
+
expect(contact.links).toStrictEqual([{ title: 'foo', href: 'bar' }])
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test(`should be optional`, () => {
|
|
93
|
+
const contact = new Contact(contactDataFixture.omit('links').create())
|
|
94
|
+
expect(contact.links).toHaveLength(0)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
})
|