-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathentityIdRegression.test.ts
More file actions
355 lines (308 loc) · 15.2 KB
/
Copy pathentityIdRegression.test.ts
File metadata and controls
355 lines (308 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
* Entity ID regression tests.
*
* These tests verify that entity IDs produced by TS park implementations
* match the expected format and don't change unexpectedly. Entity ID
* stability is critical because the ThemeParks.wiki collector agent
* references entities by ID — changed IDs would corrupt the database.
*
* Tests cover:
* 1. ID format validation (string, non-empty, no null/undefined)
* 2. Destination/park ID patterns per framework
* 3. Entity hierarchy consistency (parentId references valid entities)
* 4. No duplicate IDs within a destination
*/
import { describe, test, expect, afterAll } from 'vitest';
import { Destination } from '../destination.js';
import { Entity } from '@themeparks/typelib';
import { stopHttpQueue } from '../http.js';
import { getAllDestinations } from '../destinationRegistry.js';
afterAll(() => {
stopHttpQueue();
});
describe('Entity ID format validation', () => {
test('all registered destinations have valid IDs', async () => {
const destinations = await getAllDestinations();
expect(destinations.length).toBeGreaterThan(0);
for (const dest of destinations) {
expect(dest.id).toBeTruthy();
expect(typeof dest.id).toBe('string');
expect(dest.id).not.toBe('null');
expect(dest.id).not.toBe('undefined');
expect(dest.id.trim()).toBe(dest.id); // no leading/trailing whitespace
}
});
test('all registered destinations have valid names', async () => {
const destinations = await getAllDestinations();
for (const dest of destinations) {
expect(dest.name).toBeTruthy();
expect(typeof dest.name).toBe('string');
expect(dest.name.length).toBeGreaterThan(0);
}
});
test('no duplicate destination IDs', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
const uniqueIds = new Set(ids);
const duplicates = ids.filter((id, i) => ids.indexOf(id) !== i);
expect(duplicates).toEqual([]);
expect(uniqueIds.size).toBe(ids.length);
});
});
describe('Destination ID patterns', () => {
test('Universal destinations use expected ID format', async () => {
const destinations = await getAllDestinations();
const universal = destinations.filter(d =>
Array.isArray(d.category) ? d.category.includes('Universal') : d.category === 'Universal'
);
expect(universal.length).toBe(5);
for (const u of universal) {
// Universal IDs are derived from class name: universalorlando, universalstudios, universalstudiosbeijing, universalstudiosjapan, universalsingapore
expect(u.id).toMatch(/^universal/);
}
});
test('Six Flags framework is registered as a single destination entry', async () => {
const destinations = await getAllDestinations();
const sixflags = destinations.filter(d =>
Array.isArray(d.category) ? d.category.includes('Six Flags') : d.category === 'Six Flags'
);
// The original framework class (handles 25+ US parks via Firebase config)
// must be exactly one entry — it must not have been double-registered.
const framework = sixflags.filter(d => d.id === 'sixflags');
expect(framework.length).toBe(1);
// Other Six Flags-branded destinations with their own API (e.g. Qiddiya
// City) may also live in this category — they're separate entries.
});
test('Parcs Reunidos parks are registered individually', async () => {
const destinations = await getAllDestinations();
const pr = destinations.filter(d =>
Array.isArray(d.category) ? d.category.includes('Parcs Reunidos') : d.category === 'Parcs Reunidos'
);
// 5 parks (Kennywood moved to HFE)
expect(pr.length).toBe(5);
const ids = pr.map(d => d.id).sort();
expect(ids).toContain('movieparkgermany');
expect(ids).toContain('bobbejaanland');
expect(ids).toContain('mirabilandia');
});
test('HFE parks are registered individually', async () => {
const destinations = await getAllDestinations();
const hfe = destinations.filter(d =>
Array.isArray(d.category) ? d.category.includes('Herschend') : d.category === 'Herschend'
);
expect(hfe.length).toBe(3);
const ids = hfe.map(d => d.id).sort();
expect(ids).toContain('dollywood');
expect(ids).toContain('silverdollarcity');
expect(ids).toContain('kennywood');
});
test('Six Flags class covers both Six Flags and Cedar Fair parks', async () => {
// After the Cedar Fair / Six Flags merger the individual Cedar Fair
// apps were retired in favour of the unified Six Flags app, so parksapi
// models all of them through a single dynamic destination class.
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('sixflags');
});
test('Valleyfair park class is registered under the Enchanted Parks umbrella', async () => {
// Registry id: `@destinationController` derives this from the class name.
// `class Valleyfair` registers as `valleyfair` — same as the dropped cedarfair
// class did, so consumers that look up parks by registry id stay compatible.
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('valleyfair');
const vf = destinations.find(d => d.id === 'valleyfair');
expect(vf?.category).toEqual(['Enchanted Parks', 'Valleyfair']);
});
test('Valleyfair emits enchantedparks-namespaced DESTINATION entity id', async () => {
// Entity id (distinct from registry id): the actual id on the DESTINATION
// entity returned by getDestinations(). The old cedarfair class emitted
// `valleyfair`; the new class emits `enchantedparks_valleyfair` so the
// umbrella's namespace is used consistently.
const {Valleyfair} = await import('../parks/enchantedparks/valleyfair.js');
const dest = new Valleyfair({});
const destinations = await dest.getDestinations();
expect(destinations[0]?.id).toBe('enchantedparks_valleyfair');
expect(destinations[0]?.id).not.toBe('valleyfair');
});
test('Worlds of Fun park class is registered under the Enchanted Parks umbrella', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('worldsoffun');
const wof = destinations.find(d => d.id === 'worldsoffun');
expect(wof?.category).toEqual(['Enchanted Parks', 'Worlds of Fun']);
});
test('Worlds of Fun emits enchantedparks-namespaced DESTINATION entity id', async () => {
const {WorldsOfFun} = await import('../parks/enchantedparks/worldsoffun.js');
const dest = new WorldsOfFun({});
const destinations = await dest.getDestinations();
expect(destinations[0]?.id).toBe('enchantedparks_worldsoffun');
expect(destinations[0]?.id).not.toBe('worldsoffun');
});
test('Michigan\'s Adventure park class is registered under the Enchanted Parks umbrella', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('michigansadventure');
const ma = destinations.find(d => d.id === 'michigansadventure');
expect(ma?.category).toEqual(['Enchanted Parks', 'Michigan\'s Adventure']);
});
test('Michigan\'s Adventure emits enchantedparks-namespaced DESTINATION entity id', async () => {
const {MichigansAdventure} = await import('../parks/enchantedparks/michigansadventure.js');
const dest = new MichigansAdventure({});
const destinations = await dest.getDestinations();
expect(destinations[0]?.id).toBe('enchantedparks_michigansadventure');
expect(destinations[0]?.id).not.toBe('michigansadventure');
});
test('Mid-America Parks class is registered under the Enchanted Parks umbrella', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('midamericaparks');
const map = destinations.find(d => d.id === 'midamericaparks');
expect(map?.category).toEqual(['Enchanted Parks', 'Mid-America Parks']);
});
test('Mid-America Parks emits enchantedparks-namespaced DESTINATION entity id', async () => {
// Migrated from sixflags_destination_SFSL → enchantedparks_midamericaparks
// when EPR/Enchanted Parks took over for the 2026 season. Wiki externalId
// will be renamed to match.
const {MidAmericaParks} = await import('../parks/enchantedparks/midamericaparks.js');
const dest = new MidAmericaParks({});
const destinations = await dest.getDestinations();
expect(destinations[0]?.id).toBe('enchantedparks_midamericaparks');
expect(destinations[0]?.id).not.toBe('midamericaparks');
});
test('Great Escape Parks class is registered under the Enchanted Parks umbrella', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('greatescapeparks');
const ge = destinations.find(d => d.id === 'greatescapeparks');
expect(ge?.category).toEqual(['Enchanted Parks', 'Great Escape Parks']);
});
test('Great Escape Parks emits enchantedparks-namespaced DESTINATION entity id', async () => {
// Migrated from sixflags_destination_SFGE → enchantedparks_greatescapeparks
// when EPR/Enchanted Parks took over for the 2026 season.
const {GreatEscapeParks} = await import('../parks/enchantedparks/greatescapeparks.js');
const dest = new GreatEscapeParks({});
const destinations = await dest.getDestinations();
expect(destinations[0]?.id).toBe('enchantedparks_greatescapeparks');
expect(destinations[0]?.id).not.toBe('greatescapeparks');
});
test('Galveston Island Waterpark class is registered under the Enchanted Parks umbrella', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('galvestonislandwaterpark');
const giwp = destinations.find(d => d.id === 'galvestonislandwaterpark');
expect(giwp?.category).toEqual(['Enchanted Parks', 'Galveston Island Waterpark']);
});
test('Galveston Island Waterpark emits enchantedparks-namespaced DESTINATION entity id', async () => {
// Migrated from sixflags_destination_GV → enchantedparks_galvestonislandwaterpark
// when EPR/Enchanted Parks took over for the 2026 season.
const {GalvestonIslandWaterpark} = await import('../parks/enchantedparks/galvestonislandwaterpark.js');
const dest = new GalvestonIslandWaterpark({});
const destinations = await dest.getDestinations();
expect(destinations[0]?.id).toBe('enchantedparks_galvestonislandwaterpark');
expect(destinations[0]?.id).not.toBe('galvestonislandwaterpark');
});
test('Wuhu Dreamland (Fantawild) is registered under the Fantawild umbrella', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('wuhudreamland');
const wd = destinations.find(d => d.id === 'wuhudreamland');
expect(wd?.category).toEqual(['Fantawild']);
});
test('Wuhu Dreamland emits fantawild-namespaced DESTINATION entity id', async () => {
const {WuhuDreamland} = await import('../parks/fantawild/wuhudreamland.js');
const dest = new WuhuDreamland({});
const destinations = await dest.getDestinations();
expect(destinations[0]?.id).toBe('fantawild_wuhudreamland');
});
test('Attractions.io v1 Merlin parks are registered individually', async () => {
const destinations = await getAllDestinations();
const merlin = destinations.filter(d =>
Array.isArray(d.category) ? d.category.includes('Merlin') : d.category === 'Merlin'
);
// 15 Merlin parks (Knoebels is not Merlin)
expect(merlin.length).toBeGreaterThanOrEqual(14);
const ids = merlin.map(d => d.id);
expect(ids).toContain('altontowers');
expect(ids).toContain('thorpepark');
expect(ids).toContain('chessingtonworldofadventures');
expect(ids).toContain('legolandwindsor');
expect(ids).toContain('gardaland');
expect(ids).toContain('heidepark');
});
test('All 16 Attractions.io v1 parks are registered', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
const expectedV1Parks = [
'altontowers', 'thorpepark', 'chessingtonworldofadventures',
'legolandwindsor', 'legolandorlando', 'legolandcalifornia',
'legolandbillund', 'legolanddeutschland', 'gardaland',
'heidepark', 'knoebels', 'legolandjapan',
'djurssommerland', 'legolandnewyork', 'legolandkorea',
'peppapigthemeparkflorida',
];
for (const parkId of expectedV1Parks) {
expect(ids).toContain(parkId);
}
});
test('Parc Asterix is registered', async () => {
const destinations = await getAllDestinations();
const pa = destinations.find(d => d.id === 'parcasterix');
expect(pa).toBeDefined();
expect(pa!.name).toBe('Parc Asterix');
});
test('TE2 Australia parks are registered', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('seaworldgoldcoast');
expect(ids).toContain('warnerbrosmovieworld');
expect(ids).toContain('paradisecountry');
expect(ids).toContain('wetnwildgoldcoast');
});
test('Disney parks are registered', async () => {
const destinations = await getAllDestinations();
const ids = destinations.map(d => d.id);
expect(ids).toContain('disneylandparis');
expect(ids).toContain('tokyodisneyresort');
expect(ids).toContain('shanghaidisneylandresort');
});
});
describe('Entity ID contract rules', () => {
test('entity IDs must always be strings', () => {
// This is a compile-time guarantee from TypeScript,
// but verify the runtime behavior of String() conversion
expect(String(123)).toBe('123');
expect(String(null)).toBe('null'); // This is why we filter nulls
expect(String(undefined)).toBe('undefined');
expect(String('')).toBe('');
});
test('Six Flags entity IDs follow RIDE/SHOW/RESTAURANT-parkId-fimsId format', async () => {
// Verify the Six Flags ID format matches what the JS produces
// This is critical for backwards compatibility with the wiki database
const patterns = [
'RIDE-001-00164', // ride at park 001
'RESTAURANT-001-00002', // restaurant at park 001
'SHOW-001-00001', // show at park 001
];
for (const id of patterns) {
expect(id).toMatch(/^(RIDE|SHOW|RESTAURANT)-\d{3}-\d{5}$/);
}
});
test('Parcs Reunidos entity IDs use parquesreunidos_ prefix for destinations/parks', () => {
// The JS uses parquesreunidos_ (Spanish spelling with typo from original directory name)
const destId = 'parquesreunidos_1110';
const parkId = 'parquesreunidos_1110_park';
expect(destId).toMatch(/^parquesreunidos_\d+$/);
expect(parkId).toMatch(/^parquesreunidos_\d+_park$/);
});
test('HFE entity IDs are UUIDs', () => {
// Kennywood/Dollywood/SDC use UUID entity IDs from the CRM API
const uuid = 'acf887a6-59f6-4d70-8120-2d9fac938109';
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
});
test('Universal entity IDs are numeric strings', () => {
// Universal uses numeric IDs from the API, stored as strings
const id = '10000';
expect(id).toMatch(/^\d+$/);
});
});