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,41 @@
1
+ // API
2
+ export * from './api/alignment'
3
+ export * from './api/alternate-data'
4
+ export * from './api/archetype-data'
5
+ export * from './api/badge-data'
6
+ export * from './api/badge-requirement-data'
7
+ export * from './api/badge-requirement-type'
8
+ export * from './api/badge-type'
9
+ export * from './api/bundle-data'
10
+ export * from './api/bundle-header-data'
11
+ export * from './api/contact-data'
12
+ export * from './api/enhancement-category'
13
+ export * from './api/link'
14
+ export * from './api/location-data'
15
+ export * from './api/markdown-string'
16
+ export * from './api/mission-data'
17
+ export * from './api/mission-type'
18
+ export * from './api/morality'
19
+ export * from './api/sex'
20
+ export * from './api/zone-data'
21
+
22
+ // DB
23
+ export * from './db/alignment-list'
24
+ export * from './db/alternates'
25
+ export * from './db/archetype'
26
+ export * from './db/badge'
27
+ export * from './db/badge-index'
28
+ export * from './db/badge-requirement'
29
+ export * from './db/badge-search-options'
30
+ export * from './db/bundle-header'
31
+ export * from './db/coh-content-database'
32
+ export * from './db/contact'
33
+ export * from './db/key'
34
+ export * from './db/location'
35
+ export * from './db/mission'
36
+ export * from './db/morality-list'
37
+ export * from './db/paged'
38
+ export * from './db/zone'
39
+
40
+ // ROOT
41
+ export * from './util'
@@ -0,0 +1,118 @@
1
+ import { BadgeData } from './api/badge-data'
2
+ import { Badge } from './db/badge'
3
+ import { ZoneData } from './api/zone-data'
4
+ import { Zone } from './db/zone'
5
+ import { Contact } from './db/contact'
6
+ import { ContactData } from './api/contact-data'
7
+ import { Mission } from './db/mission'
8
+ import { MissionData } from './api/mission-data'
9
+
10
+ /**
11
+ * Returns the URI of the given badge that can be used in {@link MarkdownString} fields.
12
+ *
13
+ * URI format: `badge://<key>`
14
+ *
15
+ * @param target The badge or badge key to target.
16
+ */
17
+ export function badgeUri(target: string | Badge | BadgeData): string {
18
+ const key = typeof target === 'string' ? target : target.key
19
+ return `badge://${key}`
20
+ }
21
+
22
+ /**
23
+ * Returns a {@link MarkdownString} link to the given badge.
24
+ *
25
+ * Link format: `[<key>](badge://<key>)`
26
+ *
27
+ * @param target The {@link Badge} or badge key to target.
28
+ */
29
+ export function badgeLink(target: string | Badge | BadgeData): string {
30
+ const key = typeof target === 'string' ? target : target.key
31
+ return `[${key}](${badgeUri(target)})`
32
+ }
33
+
34
+ /**
35
+ * Returns the URI of the given contact that can be used in {@link MarkdownString} fields.
36
+ *
37
+ * URI format: `contact://<key>`
38
+ *
39
+ * @param target The {@link Contact} or contact key to target.
40
+ */
41
+ export function contactUri(target: string | Contact | ContactData): string {
42
+ const key = typeof target === 'string' ? target : target.key
43
+ return `contact://${key}`
44
+ }
45
+
46
+ /**
47
+ * Returns a {@link MarkdownString} link to the given contact.
48
+ *
49
+ * Link format: `[<key>](contact://<key>)`
50
+ *
51
+ * @param target The {@link Contact} or contact key to target.
52
+ */
53
+ export function contactLink(target: string | Contact | ContactData): string {
54
+ const key = typeof target === 'string' ? target : target.key
55
+ return `[${key}](${contactUri(target)})`
56
+ }
57
+
58
+ /**
59
+ * Returns the URI of the given mission that can be used in {@link MarkdownString} fields.
60
+ *
61
+ * URI format: `mission://<key>`
62
+ *
63
+ * @param target The {@link Mission} or mission key to target.
64
+ */
65
+ export function missionUri(target: string | Mission | MissionData): string {
66
+ const key = typeof target === 'string' ? target : target.key
67
+ return `mission://${key}`
68
+ }
69
+
70
+ /**
71
+ * Returns a {@link MarkdownString} link to the given mission.
72
+ *
73
+ * Link format: `[<key>](mission://<key>)`
74
+ *
75
+ * @param target The {@link Mission} or mission key to target.
76
+ */
77
+ export function missionLink(target: string | Mission | MissionData): string {
78
+ const key = typeof target === 'string' ? target : target.key
79
+ return `[${key}](${missionUri(target)})`
80
+ }
81
+
82
+ /**
83
+ * Returns the URI of the given zone that can be used in {@link MarkdownString} fields.
84
+ *
85
+ * URI format: `zone://<key>`
86
+ *
87
+ * @param target The {@link Zone} or zone key to target.
88
+ */
89
+ export function zoneUri(target: string | Zone | ZoneData): string {
90
+ const key = typeof target === 'string' ? target : target.key
91
+ return `zone://${key}`
92
+ }
93
+
94
+ /**
95
+ * Returns a {@link MarkdownString} link to the given zone.
96
+ *
97
+ * Link format: `[<key>](zone://<key>)`
98
+ *
99
+ * @param target The {@link Zone} or zone key to target.
100
+ */
101
+ export function zoneLink(target: string | Zone | ZoneData): string {
102
+ const key = typeof target === 'string' ? target : target.key
103
+ return `[${key}](${zoneUri(target)})`
104
+ }
105
+
106
+ /**
107
+ * For fields that accept either an array of values or a single value, coalesces the value to an array.
108
+ *
109
+ * Arrays are returned as-is.
110
+ * Single values are returned as a single-value array.
111
+ * Undefined values are returned as undefined.
112
+ *
113
+ * @param value The value to coalesce.
114
+ */
115
+ export function coalesceToArray<T>(value?: T | T[]): T[] | undefined {
116
+ if (!value) return undefined
117
+ return Array.isArray(value) ? value as T[] : [value]
118
+ }
@@ -0,0 +1,65 @@
1
+ import { Alignment, ALIGNMENT, compareAlignment } from '../../main'
2
+
3
+ describe('ALIGNMENT', () => {
4
+ test('should be an array', () => {
5
+ expect(Array.isArray(ALIGNMENT)).toBeTruthy()
6
+ })
7
+
8
+ test('should not be empty', () => {
9
+ expect(ALIGNMENT).not.toHaveLength(0)
10
+ })
11
+
12
+ test('should contain only strings', () => {
13
+ for (const entry of ALIGNMENT) {
14
+ expect(typeof entry).toBe('string')
15
+ }
16
+ })
17
+
18
+ test('should contain all known alignments', () => {
19
+ const expected = ['hero', 'villain', 'praetorian']
20
+ for (const category of expected) {
21
+ expect(ALIGNMENT).toContain(category)
22
+ }
23
+ })
24
+ })
25
+
26
+ describe('Alignment', () => {
27
+ test('should be a usable type', () => {
28
+ const field: Alignment = 'hero'
29
+ expect(field).toBe('hero')
30
+ })
31
+ })
32
+
33
+ describe('compareAlignment', () => {
34
+ test('should return <0 if first argument comes first', () => {
35
+ expect(compareAlignment('hero', 'villain')).toBeLessThan(0)
36
+ expect(compareAlignment('hero', 'praetorian')).toBeLessThan(0)
37
+ })
38
+
39
+ test('should return >0 if second argument comes first', () => {
40
+ expect(compareAlignment('villain', 'hero')).toBeGreaterThan(0)
41
+ expect(compareAlignment('praetorian', 'hero')).toBeGreaterThan(0)
42
+ })
43
+
44
+ test('should return 0 if arguments match', () => {
45
+ expect(compareAlignment('hero', 'hero')).toBe(0)
46
+ })
47
+
48
+ test('should return 0 if both arguments are undefined', () => {
49
+ expect(compareAlignment()).toBe(0)
50
+ })
51
+
52
+ test('should work as a compare function', () => {
53
+ const unsorted: (Alignment | undefined)[] = [undefined, 'hero', 'villain', 'praetorian', undefined, 'villain', 'praetorian']
54
+ const sorted = unsorted.sort(compareAlignment)
55
+
56
+ expect(sorted).toStrictEqual(['hero', 'villain', 'villain', 'praetorian', 'praetorian', undefined, undefined])
57
+ })
58
+
59
+ test('should sort against undefined', () => {
60
+ const unsorted: (Alignment | undefined)[] = [undefined, 'hero']
61
+ const sorted = unsorted.sort(compareAlignment)
62
+
63
+ expect(sorted).toStrictEqual(['hero', undefined])
64
+ })
65
+ })
@@ -0,0 +1,8 @@
1
+ import { defineFixture } from 'efate'
2
+ import { ArchetypeData } from '../../main'
3
+
4
+ export const archetypeDataFixture = defineFixture<ArchetypeData>((t) => {
5
+ t.key.as(index => `archetype-${index}`)
6
+ t.name.as(index => `Archetype ${index}`)
7
+ t.description?.asLoremIpsum()
8
+ })
@@ -0,0 +1,8 @@
1
+ import { defineFixture } from 'efate'
2
+ import { BADGE_TYPE, BadgeData } from '../../main'
3
+
4
+ export const badgeDataFixture = defineFixture<BadgeData>((t) => {
5
+ t.key.as(index => `badge-${index}`)
6
+ t.type.pickFrom([...BADGE_TYPE])
7
+ t.name.as(index => [{ value: `Badge ${index}` }])
8
+ })
@@ -0,0 +1,15 @@
1
+ import { BadgeData } from '../../main'
2
+
3
+ // If you change this test, update the example in the README as well
4
+ export const TEST_BADGE: BadgeData = {
5
+ key: 'test-badge',
6
+ type: 'achievement',
7
+ name: [{ value: 'Test Badge' }, { alignment: 'praetorian', value: 'My Badge for Praetorians' }],
8
+ morality: ['hero', 'praetorian'],
9
+ }
10
+
11
+ describe('BadgeData', () => {
12
+ test('should be a usable interface', () => {
13
+ expect(TEST_BADGE).not.toBeUndefined()
14
+ })
15
+ })
@@ -0,0 +1,7 @@
1
+ import { defineFixture } from 'efate'
2
+ import { BADGE_REQUIREMENT_TYPE, BadgeRequirementData } from '../../main'
3
+
4
+ export const badgeRequirementDataFixture = defineFixture<BadgeRequirementData>((t) => {
5
+ t.key.as(index => `badge-requirement-${index}`)
6
+ t.type.pickFrom([...BADGE_REQUIREMENT_TYPE])
7
+ })
@@ -0,0 +1,31 @@
1
+ import { BADGE_REQUIREMENT_TYPE, BadgeRequirementType } from '../../main'
2
+
3
+ describe('BADGE_REQUIREMENT_TYPE', () => {
4
+ test('should be an array', () => {
5
+ expect(Array.isArray(BADGE_REQUIREMENT_TYPE)).toBeTruthy()
6
+ })
7
+
8
+ test('should not be empty', () => {
9
+ expect(BADGE_REQUIREMENT_TYPE).not.toHaveLength(0)
10
+ })
11
+
12
+ test('should contain only strings', () => {
13
+ for (const entry of BADGE_REQUIREMENT_TYPE) {
14
+ expect(typeof entry).toBe('string')
15
+ }
16
+ })
17
+
18
+ test('should contain all known badge requirement types', () => {
19
+ const expected = ['badge', 'invention', 'invention-plus-one', 'location', 'monument', 'mission', 'task']
20
+ for (const category of expected) {
21
+ expect(BADGE_REQUIREMENT_TYPE).toContain(category)
22
+ }
23
+ })
24
+ })
25
+
26
+ describe('BadgeRequirementType', () => {
27
+ test('should be a usable type', () => {
28
+ const field: BadgeRequirementType = 'monument'
29
+ expect(field).toBe('monument')
30
+ })
31
+ })
@@ -0,0 +1,35 @@
1
+ import { BADGE_TYPE, BadgeType } from '../../main'
2
+
3
+ describe('BADGE_TYPE', () => {
4
+ test('should be an array', () => {
5
+ expect(Array.isArray(BADGE_TYPE)).toBeTruthy()
6
+ })
7
+
8
+ test('should not be empty', () => {
9
+ expect(BADGE_TYPE).not.toHaveLength(0)
10
+ })
11
+
12
+ test('should contain only strings', () => {
13
+ for (const entry of BADGE_TYPE) {
14
+ expect(typeof entry).toBe('string')
15
+ }
16
+ })
17
+
18
+ test('should contain all known basic badge types', () => {
19
+ const expected = [
20
+ 'exploration', 'history', 'accomplishment', 'achievement', 'accolade',
21
+ 'gladiator', 'veteran', 'pvp', 'invention', 'defeat',
22
+ 'event', 'ouroboros', 'consignment', 'day-job', 'architect-entertainment',
23
+ ]
24
+ for (const category of expected) {
25
+ expect(BADGE_TYPE).toContain(category)
26
+ }
27
+ })
28
+ })
29
+
30
+ describe('BadgeType', () => {
31
+ test('should be a usable type', () => {
32
+ const field: BadgeType = 'exploration'
33
+ expect(field).toBe('exploration')
34
+ })
35
+ })
@@ -0,0 +1,6 @@
1
+ import { defineFixture } from 'efate'
2
+ import { BundleData } from '../../main'
3
+
4
+ export const bundleDataFixture = defineFixture<BundleData>(() => {
5
+ // no mandatory fields
6
+ })
@@ -0,0 +1,6 @@
1
+ import { defineFixture } from 'efate'
2
+ import { BundleHeaderData } from '../../main'
3
+
4
+ export const bundleHeaderDataFixture = defineFixture<BundleHeaderData>(() => {
5
+ // no mandatory fields
6
+ })
@@ -0,0 +1,7 @@
1
+ import { defineFixture } from 'efate'
2
+ import { ContactData } from '../../main'
3
+
4
+ export const contactDataFixture = defineFixture<ContactData>((t) => {
5
+ t.key.as(index => `contact-${index}`)
6
+ t.name.as(index => [{ value: `Contact ${index}` }])
7
+ })
@@ -0,0 +1,35 @@
1
+ import { ENHANCEMENT_CATEGORY, EnhancementCategory } from '../../main'
2
+
3
+ describe('ENHANCEMENT_CATEGORY', () => {
4
+ test('should be an array', () => {
5
+ expect(Array.isArray(ENHANCEMENT_CATEGORY)).toBeTruthy()
6
+ })
7
+
8
+ test('should not be empty', () => {
9
+ expect(ENHANCEMENT_CATEGORY).not.toHaveLength(0)
10
+ })
11
+
12
+ test('should contain only strings', () => {
13
+ for (const entry of ENHANCEMENT_CATEGORY) {
14
+ expect(typeof entry).toBe('string')
15
+ }
16
+ })
17
+
18
+ test('should contain all known default enhancement categories', () => {
19
+ const expected = [
20
+ 'defense-debuff', 'to-hit-debuff', 'taunt', 'confuse', 'healing', 'defense-buff', 'resist-damage', 'intangibility', 'sleep', 'slow', 'hold', 'stun', 'immobilize',
21
+ 'fear', 'endurance-modification', 'endurance-reduction', 'recharge-reduction', 'interrupt-duration', 'accuracy', 'to-hit-buff', 'damage', 'knockback', 'run-speed',
22
+ 'jump', 'fly-speed', 'range',
23
+ ]
24
+ for (const category of expected) {
25
+ expect(ENHANCEMENT_CATEGORY).toContain(category)
26
+ }
27
+ })
28
+ })
29
+
30
+ describe('EnhancementCategory', () => {
31
+ test('should be a usable type', () => {
32
+ const field: EnhancementCategory = 'run-speed'
33
+ expect(field).toBe('run-speed')
34
+ })
35
+ })
@@ -0,0 +1,12 @@
1
+ import { defineFixture } from 'efate'
2
+ import { MISSION_TYPE, MissionData, MissionFlashbackData } from '../../main'
3
+
4
+ export const missionDataFixture = defineFixture<MissionData>((t) => {
5
+ t.key.as(index => `mission-${index}`)
6
+ t.name.as(index => `Mission ${index}`)
7
+ t.type.pickFrom([...MISSION_TYPE])
8
+ })
9
+
10
+ export const missionFlashbackDataFixture = defineFixture<MissionFlashbackData>((t) => {
11
+ t.id.as(index => `${index}.${index}`)
12
+ })
@@ -0,0 +1,63 @@
1
+ import { compareSex, Sex, SEX } from '../../main'
2
+
3
+ describe('SEX', () => {
4
+ test('should be an array', () => {
5
+ expect(Array.isArray(SEX)).toBeTruthy()
6
+ })
7
+
8
+ test('should not be empty', () => {
9
+ expect(SEX).not.toHaveLength(0)
10
+ })
11
+
12
+ test('should contain only strings', () => {
13
+ for (const entry of SEX) {
14
+ expect(typeof entry).toBe('string')
15
+ }
16
+ })
17
+
18
+ test('should contain all known sexes', () => {
19
+ const expected = ['M', 'F']
20
+ for (const category of expected) {
21
+ expect(SEX).toContain(category)
22
+ }
23
+ })
24
+ })
25
+
26
+ describe('Sex', () => {
27
+ test('should be a usable type', () => {
28
+ const field: Sex = 'M'
29
+ expect(field).toBe('M')
30
+ })
31
+ })
32
+
33
+ describe('compareSex', () => {
34
+ test('should return <0 if first argument comes first', () => {
35
+ expect(compareSex('M', 'F')).toBeLessThan(0)
36
+ })
37
+
38
+ test('should return >0 if second argument comes first', () => {
39
+ expect(compareSex('F', 'M')).toBeGreaterThan(0)
40
+ })
41
+
42
+ test('should return 0 if arguments match', () => {
43
+ expect(compareSex('F', 'F')).toBe(0)
44
+ })
45
+
46
+ test('should return 0 if both arguments are undefined', () => {
47
+ expect(compareSex()).toBe(0)
48
+ })
49
+
50
+ test('should work as a compare function', () => {
51
+ const unsorted: (Sex | undefined)[] = [undefined, 'M', 'F', 'M', undefined, 'F', 'M']
52
+ const sorted = unsorted.sort(compareSex)
53
+
54
+ expect(sorted).toStrictEqual(['M', 'M', 'M', 'F', 'F', undefined, undefined])
55
+ })
56
+
57
+ test('should sort against undefined', () => {
58
+ const unsorted: (Sex | undefined)[] = [undefined, 'M']
59
+ const sorted = unsorted.sort(compareSex)
60
+
61
+ expect(sorted).toStrictEqual(['M', undefined])
62
+ })
63
+ })
@@ -0,0 +1,8 @@
1
+ import { ZoneData } from '../../main'
2
+ import { defineFixture } from 'efate'
3
+
4
+ export const zoneDataFixture = defineFixture<ZoneData>((t) => {
5
+ t.key.as(index => `zone-${index}`)
6
+ t.name.as(index => `Zone ${index}`)
7
+ t.links?.as(() => [{ title: 'foo', href: 'https://nouri.org' }])
8
+ })
@@ -0,0 +1,55 @@
1
+ import { AbstractIndex } from '../../main/db/abstract-index'
2
+
3
+ interface TestObject {
4
+ key: string
5
+ otherValue: number
6
+ }
7
+
8
+ describe(AbstractIndex.name, () => {
9
+ describe('Constructor', () => {
10
+ test(`should accept the key field`, () => {
11
+ new AbstractIndex<TestObject>('key', [])
12
+ })
13
+
14
+ test(`should throw an error on duplicate key`, () => {
15
+ expect(() => new AbstractIndex<TestObject>('key', [
16
+ { key: '1', otherValue: 1 },
17
+ { key: '1', otherValue: 1 },
18
+ ])).toThrow('Duplicate key [1]')
19
+ })
20
+ })
21
+
22
+ describe('value', () => {
23
+ test(`should return the original values`, () => {
24
+ const values = [
25
+ { key: '1', otherValue: 1 },
26
+ { key: '2', otherValue: 2 },
27
+ ]
28
+ const index = new AbstractIndex<TestObject>('key', values)
29
+ expect(index.values).toStrictEqual(values)
30
+ })
31
+ })
32
+
33
+ describe('get', () => {
34
+ test(`should return the indexed value on match`, () => {
35
+ const index = new AbstractIndex<TestObject>('key', [
36
+ { key: '1', otherValue: 1 },
37
+ { key: '2', otherValue: 2 },
38
+ ])
39
+
40
+ expect(index.get('2')).toStrictEqual({ key: '2', otherValue: 2 })
41
+ })
42
+
43
+ test(`should return undefined on no match`, () => {
44
+ const index = new AbstractIndex<TestObject>('key', [])
45
+
46
+ expect(index.get('2')).toBeUndefined()
47
+ })
48
+
49
+ test(`should return undefined on undefined key`, () => {
50
+ const index = new AbstractIndex<TestObject>('key', [])
51
+ const key = undefined
52
+ expect(index.get(key)).toBeUndefined()
53
+ })
54
+ })
55
+ })