Skip to content

Commit

Permalink
[!] Use attr names for Walibi Holland IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
cubehouse committed May 8, 2024
1 parent 335594b commit a9a4327
Showing 1 changed file with 10 additions and 49 deletions.
59 changes: 10 additions & 49 deletions lib/parks/bellewaerde/walibiholland.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export class WalibiHolland extends Destination {
];
}

nameToId(name) {
// replace any non-word characters with nothing
return name.toLowerCase().replace(/[^\w]+/g, '');
}

/**
* Build the attraction entities for this destination
*/
Expand All @@ -118,7 +123,7 @@ export class WalibiHolland extends Destination {
...entity,
// use the array idx as our unique ID... not ideal but it's all we have
// Walibi API doesn't provide any kind of unique IDs for attractions
_id: `attr_${idx}`,
_id: `attr_${this.nameToId(x.title)}`,
_parkId: this.config.parkSlug,
_parentId: this.config.parkSlug,
_destinationId: this.config.destinationSlug,
Expand Down Expand Up @@ -149,7 +154,7 @@ export class WalibiHolland extends Destination {
...entity,
// use the array idx as our unique ID... not ideal but it's all we have
// Walibi API doesn't provide any kind of unique IDs for attractions
_id: `dining_${idx}`,
_id: `dining_${this.nameToId(x.title)}`,
_parkId: this.config.parkSlug,
_parentId: this.config.parkSlug,
_destinationId: this.config.destinationSlug,
Expand All @@ -174,13 +179,13 @@ export class WalibiHolland extends Destination {
// this function should return all the live data for all entities in this destination
return waitData.map((entry) => {
// find matching attraction data
const attractionIdx = attractionData.findIndex((x) => x.waitingTimeName === entry.id);
if (attractionIdx === -1) {
const attraction = attractionData.find((x) => x.waitingTimeName === entry.id);
if (!attraction) {
return null;
}

const data = {
_id: `attr_${attractionIdx}`,
_id: `attr_${this.nameToId(attraction.title)}`,
status: statusType.operating,
};

Expand Down Expand Up @@ -288,48 +293,4 @@ export class WalibiHolland extends Destination {
}
];
}

async unittest_attractionIdStability(logSuccess, logError) {
const ids = [
{_id: 'attr_18', _name: 'Lost Gravity'},
{_id: 'attr_1', _name: 'Eat my Dust'},
{_id: 'attr_20', _name: 'El Rio Grande'},
{_id: 'attr_28', _name: 'Goliath'},
{_id: 'attr_26', _name: 'UNTAMED'},
{_id: 'attr_17', _name: 'Space Shot'},
{_id: 'attr_24', _name: 'Speed Of Sound'},
{_id: 'attr_19', _name: 'Xpress: Platform 13'},
{_id: 'attr_12', _name: 'Crazy River'},
{_id: 'attr_11', _name: 'Condor'},
{_id: 'attr_22', _name: 'Blast'},
{_id: 'attr_25', _name: "Merlin's Magic Castle"}
];

let attractionsUnstable = false;

// get all attraction entities
const ents = await this.buildAttractionEntities();
// test each _id and name
for (const data of ids) {
const ent = ents.find((x) => x._id === data._id);
if (!ent) {
logError(`Missing entity ${data._id} - no longer present in API`);
attractionsUnstable = true;
} else {
// check name still matches
if (ent.name != data._name) {
logError(`Name mismatch for ${data._id}: ${ent.name} != ${data._name}`);
attractionsUnstable = true;
} else {
logSuccess(`${data._id} - ${data._name}`);
}
}
}

if (attractionsUnstable) {
throw new Error('Attraction IDs are unstable');
} else {
logSuccess('Attraction IDs are currently stable for Walibi Holland');
}
}
}

0 comments on commit a9a4327

Please sign in to comment.