coh-content-db 2.0.0-rc.1 → 2.0.0-rc.11

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 (100) hide show
  1. package/.editorconfig +10 -11
  2. package/.github/workflows/build.yml +4 -2
  3. package/.github/workflows/pull-request.yml +1 -1
  4. package/.github/workflows/release.yml +2 -2
  5. package/CHANGELOG.md +43 -0
  6. package/README.md +52 -24
  7. package/dist/coh-content-db.d.ts +678 -279
  8. package/dist/coh-content-db.js +828 -371
  9. package/dist/coh-content-db.js.map +1 -1
  10. package/dist/coh-content-db.mjs +803 -362
  11. package/dist/coh-content-db.mjs.map +1 -1
  12. package/eslint.config.mjs +1 -0
  13. package/package.json +1 -1
  14. package/src/main/api/alignment.ts +18 -2
  15. package/src/main/api/alternate-data.ts +2 -2
  16. package/src/main/api/badge-data.ts +20 -48
  17. package/src/main/api/badge-requirement-data.ts +64 -0
  18. package/src/main/api/badge-requirement-type.ts +32 -0
  19. package/src/main/api/badge-type.ts +15 -15
  20. package/src/main/api/bundle-data.ts +47 -0
  21. package/src/main/api/bundle-header-data.ts +37 -0
  22. package/src/main/api/contact-data.ts +48 -0
  23. package/src/main/api/enhancement-category.ts +26 -26
  24. package/src/main/api/location-data.ts +28 -0
  25. package/src/main/api/markdown-string.ts +4 -0
  26. package/src/main/api/mission-data.ts +83 -0
  27. package/src/main/api/mission-type.ts +2 -0
  28. package/src/main/api/morality.ts +31 -0
  29. package/src/main/api/sex.ts +8 -1
  30. package/src/main/api/zone-data.ts +20 -0
  31. package/src/main/db/abstract-index.ts +37 -0
  32. package/src/main/db/alignment-list.ts +54 -0
  33. package/src/main/db/alternates.ts +28 -42
  34. package/src/main/db/badge-index.ts +60 -0
  35. package/src/main/db/badge-requirement.ts +81 -0
  36. package/src/main/db/badge-search-options.ts +47 -0
  37. package/src/main/db/badge.ts +76 -71
  38. package/src/main/db/bundle-header.ts +44 -0
  39. package/src/main/db/coh-content-database.ts +123 -14
  40. package/src/main/db/contact.ts +62 -0
  41. package/src/main/db/location.ts +30 -0
  42. package/src/main/db/mission.ts +107 -0
  43. package/src/main/db/morality-list.ts +99 -0
  44. package/src/main/db/paged.ts +7 -0
  45. package/src/main/db/zone.ts +28 -0
  46. package/src/main/index.ts +23 -15
  47. package/src/main/util.ts +108 -7
  48. package/src/test/api/alignment.test.ts +38 -4
  49. package/src/test/api/badge-data.fixture.ts +1 -15
  50. package/src/test/api/badge-data.test.ts +4 -4
  51. package/src/test/api/badge-requirement-data.fixture.ts +7 -0
  52. package/src/test/api/badge-requirement-type.test.ts +31 -0
  53. package/src/test/api/badge-type.test.ts +5 -5
  54. package/src/test/api/bundle-data.fixture.ts +6 -0
  55. package/src/test/api/bundle-header-data.fixture.ts +6 -0
  56. package/src/test/api/contact-data.fixture.ts +7 -0
  57. package/src/test/api/enhancement-category.test.ts +5 -5
  58. package/src/test/api/mission-data.fixture.ts +12 -0
  59. package/src/test/api/sex.test.ts +33 -1
  60. package/src/test/api/zone-data.fixture.ts +8 -0
  61. package/src/test/db/abstract-index.test.ts +55 -0
  62. package/src/test/db/alignment-list.test.ts +200 -0
  63. package/src/test/db/alternates.test.ts +82 -117
  64. package/src/test/db/badge-index.test.ts +547 -0
  65. package/src/test/db/badge-requirement.test.ts +145 -0
  66. package/src/test/db/badge.test.ts +322 -14
  67. package/src/test/db/bundle-header.test.ts +76 -0
  68. package/src/test/db/coh-content-database.test.ts +264 -24
  69. package/src/test/db/contact.test.ts +97 -0
  70. package/src/test/db/location.test.ts +51 -0
  71. package/src/test/db/mission.test.ts +171 -0
  72. package/src/test/db/morality-list.test.ts +457 -0
  73. package/src/test/db/zone.test.ts +36 -0
  74. package/src/test/integration.test.ts +16 -0
  75. package/src/test/util.test.ts +144 -18
  76. package/src/main/api/badge-partial-data.ts +0 -65
  77. package/src/main/api/badge-partial-type.ts +0 -8
  78. package/src/main/api/change.ts +0 -14
  79. package/src/main/api/game-map-data.ts +0 -26
  80. package/src/main/api/plaque-type.ts +0 -6
  81. package/src/main/api/server-group-data.ts +0 -65
  82. package/src/main/api/vidiot-map-data.ts +0 -18
  83. package/src/main/api/vidiot-map-point-of-interest-data.ts +0 -30
  84. package/src/main/changelog.ts +0 -20
  85. package/src/main/db/badge-partial.ts +0 -35
  86. package/src/main/db/game-map.ts +0 -33
  87. package/src/main/db/server-group.ts +0 -112
  88. package/src/main/db/vidiot-map-point-of-interest.ts +0 -40
  89. package/src/main/db/vidiot-map.ts +0 -25
  90. package/src/test/api/badge-partial-data.fixture.ts +0 -17
  91. package/src/test/api/badge-partial-type.test.ts +0 -31
  92. package/src/test/api/game-map-data.fixture.ts +0 -10
  93. package/src/test/api/plaque-type.test.ts +0 -31
  94. package/src/test/api/server-group-data.fixture.ts +0 -23
  95. package/src/test/api/server-group-data.test.ts +0 -15
  96. package/src/test/api/vidiot-map-point-of-interest.fixture.ts +0 -10
  97. package/src/test/api/vidiot-map.fixture.ts +0 -9
  98. package/src/test/changelog.test.ts +0 -36
  99. package/src/test/db/server-group.test.ts +0 -124
  100. package/src/test/index.test.ts +0 -10
@@ -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
+ })
@@ -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 { 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,341 @@ describe(Badge.name, () => {
9
9
  })
10
10
  })
11
11
 
12
- describe('partials', () => {
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
- partials: [
16
- badgePartialDataFixture.create({ key: 'foo' }),
17
- badgePartialDataFixture.create({ key: 'foo' }),
156
+ key: 'badge',
157
+ requirements: [
158
+ badgeRequirementDataFixture.create({ key: 'foo' }),
159
+ badgeRequirementDataFixture.create({ key: 'foo' }),
160
+ ],
161
+ })
162
+ expect(() => new Badge(data)).toThrow('Duplicate key [foo]')
163
+ })
164
+
165
+ test(`should return requirement list`, () => {
166
+ const data = badgeDataFixture.create({
167
+ requirements: [
168
+ badgeRequirementDataFixture.create({ key: 'foo' }),
169
+ badgeRequirementDataFixture.create({ key: 'bar' }),
18
170
  ],
19
171
  })
20
- expect(() => new Badge(data)).toThrow('Duplicate badge partial key [foo]')
172
+ const badge = new Badge(data)
173
+
174
+ expect(badge.requirements.map(x => x.key)).toStrictEqual(['foo', 'bar'])
21
175
  })
22
176
  })
23
177
 
24
- describe('getBadgePartial', () => {
25
- test(`should retrieve partial from the index`, () => {
178
+ describe('getRequirement', () => {
179
+ test(`should retrieve requirement from the index`, () => {
26
180
  const data = badgeDataFixture.create({
27
- partials: [badgePartialDataFixture.create({ key: 'foo' })],
181
+ requirements: [badgeRequirementDataFixture.create({ key: 'foo' })],
28
182
  })
29
183
 
30
- expect(new Badge(data).getPartial('foo')).not.toBeNull()
184
+ expect(new Badge(data).getRequirement('foo')).not.toBeUndefined()
31
185
  })
32
186
 
33
- test(`should throw error for unknown partial`, () => {
187
+ test(`should return undefined for unknown requirement`, () => {
34
188
  const data = badgeDataFixture.create({
35
- partials: [],
189
+ requirements: [],
36
190
  })
37
191
 
38
- expect(() => new Badge(data).getPartial('foo')).toThrow('Unknown badge partial key [foo]')
192
+ expect(new Badge(data).getRequirement('foo')).toBeUndefined()
193
+ })
194
+ })
195
+
196
+ describe('zoneKeys', () => {
197
+ test(`should return the list of keys`, () => {
198
+ const badge = new Badge(badgeDataFixture.create({
199
+ requirements: [
200
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
201
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
202
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'b' } }),
203
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
204
+ ],
205
+ }))
206
+ expect(badge.zoneKeys).toStrictEqual(['a', 'c', 'b'])
207
+ })
208
+
209
+ test(`should return undefined if there no zones`, () => {
210
+ const badge = new Badge(badgeDataFixture.create({
211
+ requirements: [
212
+ badgeRequirementDataFixture.omit('location').create(),
213
+ ],
214
+ }))
215
+ expect(badge.zoneKey).toBeUndefined()
216
+ })
217
+
218
+ test(`should ignore requirements with no location`, () => {
219
+ const badge = new Badge(badgeDataFixture.create({
220
+ requirements: [
221
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
222
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
223
+ badgeRequirementDataFixture.omit('location').create(),
224
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
225
+ ],
226
+ }))
227
+ expect(badge.zoneKeys).toStrictEqual(['a', 'c'])
228
+ })
229
+ })
230
+
231
+ describe('zoneKey', () => {
232
+ test(`should return the key for a single zone`, () => {
233
+ const badge = new Badge(badgeDataFixture.create({
234
+ requirements: [
235
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
236
+ ],
237
+ }))
238
+ expect(badge.zoneKey).toBe('a')
239
+ })
240
+
241
+ test(`should return undefined if there no zones`, () => {
242
+ const badge = new Badge(badgeDataFixture.create({
243
+ requirements: [
244
+ badgeRequirementDataFixture.omit('location').create(),
245
+ ],
246
+ }))
247
+ expect(badge.zoneKey).toBeUndefined()
248
+ })
249
+
250
+ test(`should return undefined if there are multiple zones`, () => {
251
+ const badge = new Badge(badgeDataFixture.create({
252
+ requirements: [
253
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
254
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
255
+ ],
256
+ }))
257
+ expect(badge.zoneKey).toBeUndefined()
258
+ })
259
+ })
260
+
261
+ describe(compareByDefaultName.name, () => {
262
+ test(`should compare two badges by name`, () => {
263
+ const badgeA = new Badge(badgeDataFixture.create({ name: 'A' }))
264
+ const badgeB = new Badge(badgeDataFixture.create({ name: 'B' }))
265
+ expect(compareByDefaultName(badgeA, badgeB)).toBeLessThan(0)
266
+ expect([badgeB, badgeA].sort(compareByDefaultName)).toStrictEqual([badgeA, badgeB])
267
+ })
268
+
269
+ test(`should return 0 for equal names`, () => {
270
+ const badgeA = new Badge(badgeDataFixture.create({ name: 'A' }))
271
+ const badgeB = new Badge(badgeDataFixture.create({ name: 'A' }))
272
+ expect(compareByDefaultName(badgeA, badgeB)).toEqual(0)
273
+ })
274
+
275
+ test(`should compare two undefined values`, () => {
276
+ const badgeA = new Badge(badgeDataFixture.create({ name: [] }))
277
+ const badgeB = new Badge(badgeDataFixture.create({ name: [] }))
278
+ expect(compareByDefaultName(badgeA, badgeB)).toEqual(0)
279
+ })
280
+
281
+ test(`should sort undefined values last`, () => {
282
+ const badgeA = new Badge(badgeDataFixture.create({ name: 'A' }))
283
+ const badgeB = new Badge(badgeDataFixture.create({ name: [] }))
284
+ expect([badgeA, badgeB].sort(compareByDefaultName)).toStrictEqual([badgeA, badgeB])
285
+ expect([badgeB, badgeA].sort(compareByDefaultName)).toStrictEqual([badgeA, badgeB])
286
+ })
287
+ })
288
+
289
+ describe(compareByZoneKey.name, () => {
290
+ test(`should compare two badges by zoneKey`, () => {
291
+ const badgeA = new Badge(badgeDataFixture.create({
292
+ requirements: [
293
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
294
+ ],
295
+ }))
296
+ const badgeB = new Badge(badgeDataFixture.create({
297
+ requirements: [
298
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'b' } }),
299
+ ],
300
+ }))
301
+ expect(compareByZoneKey(badgeA, badgeB)).toBeLessThan(0)
302
+ expect([badgeB, badgeA].sort(compareByZoneKey)).toStrictEqual([badgeA, badgeB])
303
+ })
304
+
305
+ test(`should return 0 for equal zoneKeys`, () => {
306
+ const badgeA = new Badge(badgeDataFixture.create({
307
+ requirements: [
308
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
309
+ ],
310
+ }))
311
+ const badgeB = new Badge(badgeDataFixture.create({
312
+ requirements: [
313
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
314
+ ],
315
+ }))
316
+ expect(compareByZoneKey(badgeA, badgeB)).toEqual(0)
317
+ })
318
+
319
+ test(`should equate two undefined values`, () => {
320
+ const badgeA = new Badge(badgeDataFixture.create({
321
+ requirements: [
322
+ badgeRequirementDataFixture.omit('location').create(),
323
+ ],
324
+ }))
325
+ const badgeB = new Badge(badgeDataFixture.create({
326
+ requirements: [
327
+ badgeRequirementDataFixture.omit('location').create(),
328
+ ],
329
+ }))
330
+ expect(compareByZoneKey(badgeA, badgeB)).toEqual(0)
331
+ })
332
+
333
+ test(`should sort badges with multiple values last`, () => {
334
+ const badgeA = new Badge(badgeDataFixture.create({
335
+ requirements: [
336
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'a' } }),
337
+ ],
338
+ }))
339
+ const badgeB = new Badge(badgeDataFixture.create({
340
+ requirements: [
341
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'b' } }),
342
+ badgeRequirementDataFixture.create({ location: { zoneKey: 'c' } }),
343
+ ],
344
+ }))
345
+ expect([badgeA, badgeB].sort(compareByZoneKey)).toStrictEqual([badgeA, badgeB])
346
+ expect([badgeB, badgeA].sort(compareByZoneKey)).toStrictEqual([badgeA, badgeB])
39
347
  })
40
348
  })
41
349
  })
@@ -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
+ })