From d5e3fd9d8968a00952ea51e81ca9167b97e45a41 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Thu, 13 Apr 2023 20:13:46 -0400 Subject: [PATCH 1/2] Add Moussu Picchu stage test --- .../stages/environments/moussuPicchu.spec.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/scripts/modules/stages/environments/moussuPicchu.spec.ts diff --git a/tests/scripts/modules/stages/environments/moussuPicchu.spec.ts b/tests/scripts/modules/stages/environments/moussuPicchu.spec.ts new file mode 100644 index 00000000..6c3c62e1 --- /dev/null +++ b/tests/scripts/modules/stages/environments/moussuPicchu.spec.ts @@ -0,0 +1,31 @@ +import {addMoussuPicchuStage} from "@scripts/modules/stages/legacy"; +import {User} from "@scripts/types/hg"; +import {IntakeMessage} from "@scripts/types/mhct"; + +describe('MoussuPicchuStager', () => { + const ElementLevels = ['low', 'medium', 'high', 'max']; + + describe.each(ElementLevels)('%p rain level', (rainLevel) => { + describe.each(ElementLevels)('%p wind level', (windLevel) => { + it(`should set stage wind and rain levels to ${rainLevel} and ${windLevel}`, () => { + + const message = {} as IntakeMessage; + const preUser = {quests: {QuestMoussuPicchu: { + elements: { + rain: {level: rainLevel}, + wind: {level: windLevel}, + }, + }}} as User; + const postUser = {} as User; + const journal = {}; + addMoussuPicchuStage(message, preUser, postUser, journal); + + const expected = { + rain: `Rain ${rainLevel}`, + wind: `Wind ${windLevel}`, + }; + expect(message.stage).toStrictEqual(expected); + }); + }); + }); +}); From 134b1b66c3f9e531304b13b269c699a0d912b0b3 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Mon, 3 Apr 2023 11:40:08 -0400 Subject: [PATCH 2/2] Add Moussu Picchu stager --- src/scripts/main.js | 1 - .../stages/environments/moussuPicchu.ts | 19 +++++++++++++++++ src/scripts/modules/stages/index.ts | 2 ++ src/scripts/modules/stages/legacy.js | 15 ------------- src/scripts/types/hg.ts | 2 +- src/scripts/types/quests/index.ts | 1 + src/scripts/types/quests/moussuPicchu.ts | 15 +++++++++++++ .../stages/environments/moussuPicchu.spec.ts | 21 +++++++++++++++++-- 8 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 src/scripts/modules/stages/environments/moussuPicchu.ts create mode 100644 src/scripts/types/quests/moussuPicchu.ts diff --git a/src/scripts/main.js b/src/scripts/main.js index ca1be9d4..efba1d8a 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1211,7 +1211,6 @@ import * as detailingFuncs from './modules/details/legacy'; "Living Garden": stagingFuncs.addGardenStage, "Lost City": stagingFuncs.addLostCityStage, "Mousoleum": stagingFuncs.addMousoleumStage, - "Moussu Picchu": stagingFuncs.addMoussuPicchuStage, "Muridae Market": stagingFuncs.addMuridaeMarketStage, "Queso Geyser": stagingFuncs.addQuesoGeyserStage, "Sand Dunes": stagingFuncs.addSandDunesStage, diff --git a/src/scripts/modules/stages/environments/moussuPicchu.ts b/src/scripts/modules/stages/environments/moussuPicchu.ts new file mode 100644 index 00000000..5d06860b --- /dev/null +++ b/src/scripts/modules/stages/environments/moussuPicchu.ts @@ -0,0 +1,19 @@ +import {type User} from '@scripts/types/hg'; +import {type IntakeMessage} from '@scripts/types/mhct'; +import {type IStager} from '../stages.types'; + +export class MoussuPicchuStager implements IStager { + readonly environment: string = 'Moussu Picchu'; + + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + if (!userPre.quests.QuestMoussuPicchu) { + throw new Error('QuestMoussuPicchu is undefined'); + } + + const elements = userPre.quests.QuestMoussuPicchu.elements; + message.stage = { + rain: `Rain ${elements.rain.level}`, + wind: `Wind ${elements.wind.level}`, + }; + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index 30bfb6b9..96df6e93 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -3,6 +3,7 @@ import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk'; import {ForbiddenGroveStager} from './environments/forbiddenGrove'; import {FungalCavernStager} from './environments/fungalCavern'; import {IceFortressStager} from './environments/iceFortress'; +import {MoussuPicchuStager} from './environments/moussuPicchu'; import {SuperBrieFactoryStager} from './environments/superBrieFactory'; const stageModules: IStager[] = [ @@ -10,6 +11,7 @@ const stageModules: IStager[] = [ new ForbiddenGroveStager(), new FungalCavernStager(), new IceFortressStager(), + new MoussuPicchuStager(), new SuperBrieFactoryStager(), ]; diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index ed5433fa..1390c029 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -82,21 +82,6 @@ export function addFestiveCometStage(message, user, user_post, hunt) { } } -/** - * MP stage reflects the weather categories - * @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 addMoussuPicchuStage(message, user, user_post, hunt) { - const elements = user.quests.QuestMoussuPicchu.elements; - message.stage = { - rain: `Rain ${elements.rain.level}`, - wind: `Wind ${elements.wind.level}`, - }; -} - /** * WWR stage reflects the zones' rage categories * @param {Object } message The message to be sent. diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index 36ec80d7..a863912b 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -52,7 +52,7 @@ export interface Quests { QuestLivingGarden?: unknown QuestLostCity?: unknown QuestMousoleum?: unknown - QuestMoussuPicchu?: unknown + QuestMoussuPicchu?: quests.QuestMoussuPicchu QuestPollutionOutbreak?: unknown QuestQuesoGeyser?: unknown QuestRelicHunter?: unknown diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index 8aad9c1a..6eb98650 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -3,6 +3,7 @@ export * from '@scripts/types/quests/clawShotCity'; export * from '@scripts/types/quests/forbiddenGrove'; export * from '@scripts/types/quests/iceberg'; export * from '@scripts/types/quests/iceFortress'; +export * from '@scripts/types/quests/moussuPicchu'; export * from '@scripts/types/quests/superBrieFactory'; export * from '@scripts/types/quests/tableOfContents'; export * from '@scripts/types/quests/springHunt'; diff --git a/src/scripts/types/quests/moussuPicchu.ts b/src/scripts/types/quests/moussuPicchu.ts new file mode 100644 index 00000000..e68e4f8a --- /dev/null +++ b/src/scripts/types/quests/moussuPicchu.ts @@ -0,0 +1,15 @@ +export interface QuestMoussuPicchu { + elements: { + wind: ElementIndicator + rain: ElementIndicator + storm: { + level: 'none' | ElementLevel + } + } +} + +interface ElementIndicator { + level: ElementLevel +} + +type ElementLevel = 'low' | 'medium' | 'high' | 'max'; diff --git a/tests/scripts/modules/stages/environments/moussuPicchu.spec.ts b/tests/scripts/modules/stages/environments/moussuPicchu.spec.ts index 6c3c62e1..d9281ecc 100644 --- a/tests/scripts/modules/stages/environments/moussuPicchu.spec.ts +++ b/tests/scripts/modules/stages/environments/moussuPicchu.spec.ts @@ -1,13 +1,19 @@ -import {addMoussuPicchuStage} from "@scripts/modules/stages/legacy"; +import {MoussuPicchuStager} from "@scripts/modules/stages/environments/moussuPicchu"; import {User} from "@scripts/types/hg"; import {IntakeMessage} from "@scripts/types/mhct"; describe('MoussuPicchuStager', () => { const ElementLevels = ['low', 'medium', 'high', 'max']; + it('should be for the "Moussu Picchu" environment', () => { + const stager = new MoussuPicchuStager(); + expect(stager.environment).toBe('Moussu Picchu'); + }); + describe.each(ElementLevels)('%p rain level', (rainLevel) => { describe.each(ElementLevels)('%p wind level', (windLevel) => { it(`should set stage wind and rain levels to ${rainLevel} and ${windLevel}`, () => { + const stager = new MoussuPicchuStager(); const message = {} as IntakeMessage; const preUser = {quests: {QuestMoussuPicchu: { @@ -18,7 +24,7 @@ describe('MoussuPicchuStager', () => { }}} as User; const postUser = {} as User; const journal = {}; - addMoussuPicchuStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); const expected = { rain: `Rain ${rainLevel}`, @@ -28,4 +34,15 @@ describe('MoussuPicchuStager', () => { }); }); }); + + it.each([undefined, null])('should throw when QuestMoussuPicchu is %p', (quest) => { + const stager = new MoussuPicchuStager(); + + const message = {} as IntakeMessage; + const preUser = {quests: {QuestMoussuPicchu: quest}} as User; + const postUser = {} as User; + const journal = {}; + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestMoussuPicchu is undefined'); + }); });