diff --git a/src/scripts/main.js b/src/scripts/main.js index e3bbce69..21d3f97a 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1186,7 +1186,6 @@ import * as detailingFuncs from './modules/details/legacy'; "Furoma Rift": stagingFuncs.addFuromaRiftStage, "Gnawnian Express Station": stagingFuncs.addTrainStage, "Iceberg": stagingFuncs.addIcebergStage, - "Labyrinth": stagingFuncs.addLabyrinthStage, "Living Garden": stagingFuncs.addGardenStage, "Lost City": stagingFuncs.addLostCityStage, "Muridae Market": stagingFuncs.addMuridaeMarketStage, diff --git a/src/scripts/modules/stages/environments/labyrinth.ts b/src/scripts/modules/stages/environments/labyrinth.ts new file mode 100644 index 00000000..984841e7 --- /dev/null +++ b/src/scripts/modules/stages/environments/labyrinth.ts @@ -0,0 +1,24 @@ +import {type User} from '@scripts/types/hg'; +import {type IntakeMessage} from '@scripts/types/mhct'; +import {type IStager} from '../stages.types'; + +export class LabyrinthStager implements IStager { + readonly environment: string = 'Labyrinth'; + + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + const quest = userPre.quests.QuestLabyrinth; + + if (!quest) { + throw new Error('QuestLabyrinth is undefined'); + } + + if (quest.status === "hallway") { + const hallway = quest.hallway_name; + // Remove first word (like Short) + message.stage = hallway.substr(hallway.indexOf(" ") + 1).replace(/ hallway/i, ''); + } else { + // Not recording intersections at this time. + throw new Error('Not recording labyrinth intersections'); + } + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index 52108bb1..827452c6 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -6,6 +6,7 @@ import {ForbiddenGroveStager} from './environments/forbiddenGrove'; import {FungalCavernStager} from './environments/fungalCavern'; import {HarbourStager} from './environments/harbour'; import {IceFortressStager} from './environments/iceFortress'; +import {LabyrinthStager} from './environments/labyrinth'; import {MoussuPicchuStager} from './environments/moussuPicchu'; import {MousoleumStager} from './environments/mousoleum'; import {SuperBrieFactoryStager} from './environments/superBrieFactory'; @@ -18,6 +19,7 @@ const stageModules: IStager[] = [ new FungalCavernStager(), new HarbourStager(), new IceFortressStager(), + new LabyrinthStager(), new MoussuPicchuStager(), new MousoleumStager(), new SuperBrieFactoryStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index c2edb019..9eea2d72 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -72,24 +72,6 @@ export function addWhiskerWoodsRiftStage(message, user, user_post, hunt) { } } -/** - * Labyrinth stage reflects the type of hallway. - * @param {Object } message The message to be sent. - * @param {Object } user The user state object, when the hunt was invoked (pre-hunt). - * @param {Object } user_post The user state object, after the hunt. - * @param {Object } hunt The journal entry corresponding to the active hunt. - */ -export function addLabyrinthStage(message, user, user_post, hunt) { - if (user.quests.QuestLabyrinth.status === "hallway") { - const hallway = user.quests.QuestLabyrinth.hallway_name; - // Remove first word (like Short) - message.stage = hallway.substr(hallway.indexOf(" ") + 1).replace(/ hallway/i, ''); - } else { - // Not recording intersections at this time. - message.location = null; - } -} - /** * Stage in the FW reflects the current wave only. * @param {Object } message The message to be sent. diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index 8a8f8868..b19b925e 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -50,7 +50,7 @@ export interface Quests { QuestHalloweenBoilingCauldron?: quests.QuestHalloweenBoilingCauldron QuestIceberg?: quests.QuestIceberg; QuestIceFortress?: quests.QuestIceFortress; - QuestLabyrinth?: unknown + QuestLabyrinth?: quests.QuestLabyrinth QuestLivingGarden?: unknown QuestLostCity?: unknown QuestMousoleum?: quests.QuestMousoleum diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index fea070af..0055c358 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -6,6 +6,7 @@ export * from '@scripts/types/quests/halloween'; export * from '@scripts/types/quests/harbour'; export * from '@scripts/types/quests/iceberg'; export * from '@scripts/types/quests/iceFortress'; +export * from '@scripts/types/quests/labyrinth'; export * from '@scripts/types/quests/mousoleum'; export * from '@scripts/types/quests/moussuPicchu'; export * from '@scripts/types/quests/superBrieFactory'; diff --git a/src/scripts/types/quests/labyrinth.ts b/src/scripts/types/quests/labyrinth.ts new file mode 100644 index 00000000..48ba9b78 --- /dev/null +++ b/src/scripts/types/quests/labyrinth.ts @@ -0,0 +1,4 @@ +export interface QuestLabyrinth { + status: string; + hallway_name: string; +} diff --git a/tests/scripts/modules/stages/environments/labyrinth.spec.ts b/tests/scripts/modules/stages/environments/labyrinth.spec.ts new file mode 100644 index 00000000..c044e92a --- /dev/null +++ b/tests/scripts/modules/stages/environments/labyrinth.spec.ts @@ -0,0 +1,57 @@ +import {LabyrinthStager} from "@scripts/modules/stages/environments/labyrinth"; +import {User} from "@scripts/types/hg"; +import {IntakeMessage} from "@scripts/types/mhct"; + +describe('Labyrinth stages', () => { + const HallwayLengths = ['Short', 'Medium', 'Long']; + const HallwayTypes = ['Fealty', 'Tech', 'Scholar']; + const HallwayQualities = ['Plain', 'Superior', 'Epic']; + + const hallwayCombinations = [ + HallwayTypes, + HallwayQualities, + ].reduce((a, b) => a.flatMap(x => b.map(y => `${x} ${y}`)), ['']); + + it('should be for the "Labyrinth" environment', () => { + const stager = new LabyrinthStager(); + expect(stager.environment).toBe('Labyrinth'); + }); + + it('should throw for non hallway', () => { + const stager = new LabyrinthStager(); + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLabyrinth:{ + status: 'intersection', + }}} as User; + const postUser = {} as User; + const journal = {}; + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('Not recording labyrinth intersections'); + }); + + describe.each(hallwayCombinations)('should set hallway stage for each combination', (hallwayType) => { + it.each(HallwayLengths)('hallway length: %p', (length) => { + const stager = new LabyrinthStager(); + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLabyrinth:{ + hallway_name: `${length} ${hallwayType} Hallway`, + status: 'hallway', + }}} as User; + const postUser = {} as User; + const journal = {}; + stager.addStage(message, preUser, postUser, journal); + + expect(message.stage).toBe(hallwayType); + }); + }); + + it.each([undefined, null])('should throw when QuestLabyrinth is %p', (quest) => { + const stager = new LabyrinthStager(); + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLabyrinth: quest}} as User; + const postUser = {} as User; + const journal = {}; + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestLabyrinth is undefined'); + }); +});