From 5991a492a766358ef169b01b8cd8abbd44b0e4ca Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Sat, 15 Apr 2023 15:06:37 -0400 Subject: [PATCH 1/2] Add Labyrinth stage test --- .../stages/environments/labyrinth.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/scripts/modules/stages/environments/labyrinth.spec.ts 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..43f9be73 --- /dev/null +++ b/tests/scripts/modules/stages/environments/labyrinth.spec.ts @@ -0,0 +1,42 @@ +import {addLabyrinthStage} from "@scripts/modules/stages/legacy"; +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('show set location to null for non hallway', () => { + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLabyrinth:{ + status: 'intersection', + }}} as User; + const postUser = {} as User; + const journal = {}; + addLabyrinthStage(message, preUser, postUser, journal); + + expect(message.location).toBe(null); + }); + + describe.each(hallwayCombinations)('should set hallway stage for each combination', (hallwayType) => { + it.each(HallwayLengths)('hallway length: %p', (length) => { + + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLabyrinth:{ + hallway_name: `${length} ${hallwayType} Hallway`, + status: 'hallway', + }}} as User; + const postUser = {} as User; + const journal = {}; + addLabyrinthStage(message, preUser, postUser, journal); + + expect(message.stage).toBe(hallwayType); + }); + }); +}); From 27f73ec78bea7c3ccb929569e6e5f5ff6ce42597 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Mon, 3 Apr 2023 12:17:28 -0400 Subject: [PATCH 2/2] Add Labyrinth stager --- src/scripts/main.js | 1 - .../modules/stages/environments/labyrinth.ts | 24 +++++++++++++++ src/scripts/modules/stages/index.ts | 2 ++ src/scripts/modules/stages/legacy.js | 18 ------------ src/scripts/types/hg.ts | 2 +- src/scripts/types/quests/index.ts | 1 + src/scripts/types/quests/labyrinth.ts | 4 +++ .../stages/environments/labyrinth.spec.ts | 29 ++++++++++++++----- 8 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 src/scripts/modules/stages/environments/labyrinth.ts create mode 100644 src/scripts/types/quests/labyrinth.ts 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 index 43f9be73..c044e92a 100644 --- a/tests/scripts/modules/stages/environments/labyrinth.spec.ts +++ b/tests/scripts/modules/stages/environments/labyrinth.spec.ts @@ -1,4 +1,4 @@ -import {addLabyrinthStage} from "@scripts/modules/stages/legacy"; +import {LabyrinthStager} from "@scripts/modules/stages/environments/labyrinth"; import {User} from "@scripts/types/hg"; import {IntakeMessage} from "@scripts/types/mhct"; @@ -12,21 +12,26 @@ describe('Labyrinth stages', () => { HallwayQualities, ].reduce((a, b) => a.flatMap(x => b.map(y => `${x} ${y}`)), ['']); - it('show set location to null for non hallway', () => { + 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 = {}; - addLabyrinthStage(message, preUser, postUser, journal); - - expect(message.location).toBe(null); + 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`, @@ -34,9 +39,19 @@ describe('Labyrinth stages', () => { }}} as User; const postUser = {} as User; const journal = {}; - addLabyrinthStage(message, preUser, postUser, 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'); + }); });