From 32ce588c16d24642a41ad8b41314d7a39347b1a9 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Fri, 21 Apr 2023 17:57:29 -0400 Subject: [PATCH 1/3] Add Lost/Cursed City stage test --- .../stages/environments/lostCity.spec.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/scripts/modules/stages/environments/lostCity.spec.ts diff --git a/tests/scripts/modules/stages/environments/lostCity.spec.ts b/tests/scripts/modules/stages/environments/lostCity.spec.ts new file mode 100644 index 00000000..cd27f0a3 --- /dev/null +++ b/tests/scripts/modules/stages/environments/lostCity.spec.ts @@ -0,0 +1,31 @@ +import {addLostCityStage} from "@scripts/modules/stages/legacy"; +import {User} from "@scripts/types/hg"; +import {IntakeMessage} from "@scripts/types/mhct"; + +describe('Lost/Cursed City stages', () => { + it('should set stage to "Cursed" when user is cursed', () => { + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLostCity: {minigame: { + is_cursed: true, + }}}} as User; + const postUser = {} as User; + const journal = {}; + + addLostCityStage(message, preUser, postUser, journal); + + expect(message.stage).toBe('Cursed'); + }); + + it('should set stage to "Cursed" when user is not cursed', () => { + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLostCity: {minigame: { + is_cursed: false, + }}}} as User; + const postUser = {} as User; + const journal = {}; + + addLostCityStage(message, preUser, postUser, journal); + + expect(message.stage).toBe('Not Cursed'); + }); +}); From 0d42d00859e5bde0fe1f8944378e3e1c36900657 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Tue, 4 Apr 2023 10:15:29 -0400 Subject: [PATCH 2/3] Add Lost/Cursed City stager --- src/scripts/main.js | 2 - .../modules/stages/environments/cursedCity.ts | 20 +++++ .../modules/stages/environments/lostCity.ts | 20 +++++ src/scripts/modules/stages/index.ts | 4 + src/scripts/modules/stages/legacy.js | 12 --- src/scripts/types/hg.ts | 2 +- src/scripts/types/quests/index.ts | 1 + src/scripts/types/quests/lostCity.ts | 5 ++ .../stages/environments/lostCity.spec.ts | 73 ++++++++++++++++++- 9 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 src/scripts/modules/stages/environments/cursedCity.ts create mode 100644 src/scripts/modules/stages/environments/lostCity.ts create mode 100644 src/scripts/types/quests/lostCity.ts diff --git a/src/scripts/main.js b/src/scripts/main.js index 38ace48d..b75959bf 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1176,7 +1176,6 @@ import * as detailingFuncs from './modules/details/legacy'; const location_stage_lookup = { "Bristle Woods Rift": stagingFuncs.addBristleWoodsRiftStage, "Burroughs Rift": stagingFuncs.addBurroughsRiftStage, - "Cursed City": stagingFuncs.addLostCityStage, "Festive Comet": stagingFuncs.addFestiveCometStage, "Frozen Vacant Lot": stagingFuncs.addFestiveCometStage, "Foreword Farm": stagingFuncs.addForewordFarmStage, @@ -1184,7 +1183,6 @@ import * as detailingFuncs from './modules/details/legacy'; "Furoma Rift": stagingFuncs.addFuromaRiftStage, "Gnawnian Express Station": stagingFuncs.addTrainStage, "Iceberg": stagingFuncs.addIcebergStage, - "Lost City": stagingFuncs.addLostCityStage, "Queso Geyser": stagingFuncs.addQuesoGeyserStage, "Seasonal Garden": stagingFuncs.addSeasonalGardenStage, "Sunken City": stagingFuncs.addSunkenCityStage, diff --git a/src/scripts/modules/stages/environments/cursedCity.ts b/src/scripts/modules/stages/environments/cursedCity.ts new file mode 100644 index 00000000..88e82fa2 --- /dev/null +++ b/src/scripts/modules/stages/environments/cursedCity.ts @@ -0,0 +1,20 @@ +import {type User} from '@scripts/types/hg'; +import {type IntakeMessage} from '@scripts/types/mhct'; +import {type IStager} from '../stages.types'; + +export class CursedCityStager implements IStager { + readonly environment: string = 'Cursed City'; + + /** + * Indicate whether or not the Cursed / Corrupt mouse is present + */ + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + // TODO: Partially cursed, for Cursed City? + const quest = userPre.quests.QuestLostCity; + if (!quest) { + throw new Error('QuestLostCity is undefined'); + } + + message.stage = (quest.minigame.is_cursed) ? "Cursed" : "Not Cursed"; + } +} diff --git a/src/scripts/modules/stages/environments/lostCity.ts b/src/scripts/modules/stages/environments/lostCity.ts new file mode 100644 index 00000000..e2a1e2cf --- /dev/null +++ b/src/scripts/modules/stages/environments/lostCity.ts @@ -0,0 +1,20 @@ +import {type User} from '@scripts/types/hg'; +import {type IntakeMessage} from '@scripts/types/mhct'; +import {type IStager} from '../stages.types'; + +export class LostCityStager implements IStager { + readonly environment: string = 'Lost City'; + + /** + * Indicate whether or not the Cursed / Corrupt mouse is present + */ + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + // TODO: Partially cursed, for Cursed City? + const quest = userPre.quests.QuestLostCity; + if (!quest) { + throw new Error('QuestLostCity is undefined'); + } + + message.stage = (quest.minigame.is_cursed) ? "Cursed" : "Not Cursed"; + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index c3a80263..47bfda01 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -2,6 +2,7 @@ import {type IStager} from './stages.types'; import {BalacksCoveStager} from './environments/balacksCove'; import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk'; import {ClawShotCityStager} from './environments/clawShotCity'; +import {CursedCityStager} from './environments/cursedCity'; import {FieryWarpathStager} from './environments/fieryWarpath'; import {FloatingIslandsStager} from './environments/floatingIslands'; import {ForbiddenGroveStager} from './environments/forbiddenGrove'; @@ -10,6 +11,7 @@ import {HarbourStager} from './environments/harbour'; import {IceFortressStager} from './environments/iceFortress'; import {LabyrinthStager} from './environments/labyrinth'; import {LivingGardenStager} from './environments/livingGarden'; +import {LostCityStager} from './environments/lostCity'; import {MoussuPicchuStager} from './environments/moussuPicchu'; import {MousoleumStager} from './environments/mousoleum'; import {MuridaeMarketStager} from './environments/muridaeMarket'; @@ -22,6 +24,7 @@ const stageModules: IStager[] = [ new BalacksCoveStager(), new BountifulBeanstalkStager(), new ClawShotCityStager(), + new CursedCityStager(), new FieryWarpathStager(), new FloatingIslandsStager(), new ForbiddenGroveStager(), @@ -30,6 +33,7 @@ const stageModules: IStager[] = [ new IceFortressStager(), new LabyrinthStager(), new LivingGardenStager(), + new LostCityStager(), new MoussuPicchuStager(), new MousoleumStager(), new MuridaeMarketStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index c7954167..0bc64145 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -105,18 +105,6 @@ export function addSeasonalGardenStage(message, user, user_post, hunt) { } } -/** - * Indicate whether or not the Cursed / Corrupt mouse is present - * @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 addLostCityStage(message, user, user_post, hunt) { -// TODO: Partially cursed, for Cursed City? - message.stage = (user.quests.QuestLostCity.minigame.is_cursed) ? "Cursed" : "Not Cursed"; -} - /** * Report the current distance / obstacle. * TODO: Stage / hunt details for first & second icewing hunting? diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index 0b50d029..ef483bc8 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -52,7 +52,7 @@ export interface Quests { QuestIceFortress?: quests.QuestIceFortress; QuestLabyrinth?: quests.QuestLabyrinth QuestLivingGarden?: quests.QuestLivingGarden - QuestLostCity?: unknown + QuestLostCity?: quests.QuestLostCity QuestMousoleum?: quests.QuestMousoleum QuestMoussuPicchu?: quests.QuestMoussuPicchu QuestPollutionOutbreak?: unknown diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index 14cd0e4e..3206b947 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -9,6 +9,7 @@ export * from '@scripts/types/quests/iceberg'; export * from '@scripts/types/quests/iceFortress'; export * from '@scripts/types/quests/labyrinth'; export * from '@scripts/types/quests/livingGarden'; +export * from '@scripts/types/quests/lostCity'; export * from '@scripts/types/quests/mousoleum'; export * from '@scripts/types/quests/moussuPicchu'; export * from '@scripts/types/quests/sandDunes'; diff --git a/src/scripts/types/quests/lostCity.ts b/src/scripts/types/quests/lostCity.ts new file mode 100644 index 00000000..2aefc548 --- /dev/null +++ b/src/scripts/types/quests/lostCity.ts @@ -0,0 +1,5 @@ +export interface QuestLostCity { + minigame: { + is_cursed: boolean + } +} diff --git a/tests/scripts/modules/stages/environments/lostCity.spec.ts b/tests/scripts/modules/stages/environments/lostCity.spec.ts index cd27f0a3..107d4b1e 100644 --- a/tests/scripts/modules/stages/environments/lostCity.spec.ts +++ b/tests/scripts/modules/stages/environments/lostCity.spec.ts @@ -1,9 +1,16 @@ -import {addLostCityStage} from "@scripts/modules/stages/legacy"; +import {CursedCityStager} from "@scripts/modules/stages/environments/cursedCity"; +import {LostCityStager} from "@scripts/modules/stages/environments/lostCity"; import {User} from "@scripts/types/hg"; import {IntakeMessage} from "@scripts/types/mhct"; -describe('Lost/Cursed City stages', () => { +describe('Lost City stages', () => { + it('should be for the "" environment', () => { + const stager = new LostCityStager(); + expect(stager.environment).toBe('Lost City'); + }); + it('should set stage to "Cursed" when user is cursed', () => { + const stager = new LostCityStager(); const message = {} as IntakeMessage; const preUser = {quests: {QuestLostCity: {minigame: { is_cursed: true, @@ -11,12 +18,13 @@ describe('Lost/Cursed City stages', () => { const postUser = {} as User; const journal = {}; - addLostCityStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe('Cursed'); }); it('should set stage to "Cursed" when user is not cursed', () => { + const stager = new LostCityStager(); const message = {} as IntakeMessage; const preUser = {quests: {QuestLostCity: {minigame: { is_cursed: false, @@ -24,8 +32,65 @@ describe('Lost/Cursed City stages', () => { const postUser = {} as User; const journal = {}; - addLostCityStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe('Not Cursed'); }); + + it.each([undefined, null])('should throw when QuestLostCity is %p', (state) => { + const stager = new LostCityStager(); + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLostCity: state}} as User; + const postUser = {} as User; + const journal = {}; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestLostCity is undefined'); + }); +}); + +describe('Cursed City stages', () => { + it('should be for the "" environment', () => { + const stager = new CursedCityStager(); + expect(stager.environment).toBe('Cursed City'); + }); + + it('should set stage to "Cursed" when user is cursed', () => { + const stager = new CursedCityStager(); + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLostCity: {minigame: { + is_cursed: true, + }}}} as User; + const postUser = {} as User; + const journal = {}; + + stager.addStage(message, preUser, postUser, journal); + + expect(message.stage).toBe('Cursed'); + }); + + it('should set stage to "Cursed" when user is not cursed', () => { + const stager = new CursedCityStager(); + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLostCity: {minigame: { + is_cursed: false, + }}}} as User; + const postUser = {} as User; + const journal = {}; + + stager.addStage(message, preUser, postUser, journal); + + expect(message.stage).toBe('Not Cursed'); + }); + + it.each([undefined, null])('should throw when QuestLostCity is %p', (state) => { + const stager = new CursedCityStager(); + const message = {} as IntakeMessage; + const preUser = {quests: {QuestLostCity: state}} as User; + const postUser = {} as User; + const journal = {}; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestLostCity is undefined'); + }); }); From 499dd65c609aa27a6c1e6f548805f202f4e27b50 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Thu, 11 Jan 2024 14:58:52 -0500 Subject: [PATCH 3/3] Add missing environment names in test names --- tests/scripts/modules/stages/environments/lostCity.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/scripts/modules/stages/environments/lostCity.spec.ts b/tests/scripts/modules/stages/environments/lostCity.spec.ts index 107d4b1e..e4258785 100644 --- a/tests/scripts/modules/stages/environments/lostCity.spec.ts +++ b/tests/scripts/modules/stages/environments/lostCity.spec.ts @@ -4,7 +4,7 @@ import {User} from "@scripts/types/hg"; import {IntakeMessage} from "@scripts/types/mhct"; describe('Lost City stages', () => { - it('should be for the "" environment', () => { + it('should be for the "Lost City" environment', () => { const stager = new LostCityStager(); expect(stager.environment).toBe('Lost City'); }); @@ -50,7 +50,7 @@ describe('Lost City stages', () => { }); describe('Cursed City stages', () => { - it('should be for the "" environment', () => { + it('should be for the "Cursed City" environment', () => { const stager = new CursedCityStager(); expect(stager.environment).toBe('Cursed City'); });