From 5b5940886c1788ee289e40d656a6bad2038b602b Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Tue, 28 Feb 2023 16:33:29 -0500 Subject: [PATCH 1/2] Move SBFactory to stager module --- src/scripts/main.js | 24 -------------- .../stages/{ => environments}/iceFortress.ts | 2 +- .../stages/environments/superBrieFactory.ts | 31 +++++++++++++++++++ src/scripts/modules/stages/index.ts | 6 ++-- src/scripts/types/hg.ts | 2 +- src/scripts/types/quests/index.ts | 1 + src/scripts/types/quests/superBrieFactory.ts | 15 +++++++++ .../{ => environments}/iceFortress.spec.ts | 2 +- 8 files changed, 54 insertions(+), 29 deletions(-) rename src/scripts/modules/stages/{ => environments}/iceFortress.ts (92%) create mode 100644 src/scripts/modules/stages/environments/superBrieFactory.ts create mode 100644 src/scripts/types/quests/superBrieFactory.ts rename tests/scripts/modules/stages/{ => environments}/iceFortress.spec.ts (87%) diff --git a/src/scripts/main.js b/src/scripts/main.js index 24315df7..cd965989 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1237,7 +1237,6 @@ import * as stagers from './modules/stages'; "Moussu Picchu": addMoussuPicchuStage, "Muridae Market": addMuridaeMarketStage, "Queso Geyser": addQuesoGeyserStage, - "SUPER|brie+ Factory": addSBFactoryStage, "Sand Dunes": addSandDunesStage, "Seasonal Garden": addSeasonalGardenStage, "Slushy Shoreline": addSlushyShorelineStage, @@ -1927,29 +1926,6 @@ import * as stagers from './modules/stages'; } } - /** - * Separate boss-stage hunts from other hunts in rooms. - * @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. - */ - function addSBFactoryStage(message, user, user_post, hunt) { - const factory = user.quests.QuestSuperBrieFactory.factory_atts; - if (message.mouse === "Vincent, The Magnificent" || factory.boss_warning) { - message.stage = "Boss"; - } else { - message.stage = (({ - "pumping_room": "Pump Room", - "mixing_room": "Mixing Room", - "break_room": "Break Room", - "quality_assurance_room": "QA Room", - })[factory.current_room]); - if (!message.stage || !/Coggy Colby/.test(user.bait_name) ) { - message.stage = "Any Room"; - } - } - } /** * Report the state of corks and eruptions diff --git a/src/scripts/modules/stages/iceFortress.ts b/src/scripts/modules/stages/environments/iceFortress.ts similarity index 92% rename from src/scripts/modules/stages/iceFortress.ts rename to src/scripts/modules/stages/environments/iceFortress.ts index 8ce20e85..f5c4e3d4 100644 --- a/src/scripts/modules/stages/iceFortress.ts +++ b/src/scripts/modules/stages/environments/iceFortress.ts @@ -1,4 +1,4 @@ -import { type IStager } from './stages.types'; +import { type IStager } from '../stages.types'; import { type QuestIceFortress } from '@scripts/types/quests/iceFortress'; import { type User } from '@scripts/types/hg'; diff --git a/src/scripts/modules/stages/environments/superBrieFactory.ts b/src/scripts/modules/stages/environments/superBrieFactory.ts new file mode 100644 index 00000000..86e0fffd --- /dev/null +++ b/src/scripts/modules/stages/environments/superBrieFactory.ts @@ -0,0 +1,31 @@ +import type { IStager } from '../stages.types'; +import type { User } from '@scripts/types/hg'; +import type { RoomType } from '@scripts/types/quests'; + +export class SuperBrieFactoryStager implements IStager { + readonly environment: string = 'SUPER|brie+ Factory'; + + readonly roomTypeToStage: Record = { + "pumping_room": "Pump Room", + "mixing_room": "Mixing Room", + "break_room": "Break Room", + "quality_assurance_room": "QA Room", + } + + addStage(message: any, userPre: User, userPost: User, journal: any): void { + const quest = userPre.quests.QuestSuperBrieFactory; + + if (quest == null) { + throw new Error('User is in SB+ factory but quest wasn\'t found.'); + } + + if (message.mouse === "Vincent, The Magnificent" || quest.factory_atts.boss_warning === true) { + message.stage = "Boss"; + } else { + message.stage = this.roomTypeToStage[quest.factory_atts.current_room]; + if (!message.stage || !/Coggy Colby/.test(userPre.bait_name) ) { + message.stage = "Any Room"; + } + } + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index 216e8374..9cf7b70b 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -1,8 +1,10 @@ import { type IStager } from './stages.types'; -import { IceFortressStager } from './iceFortress'; +import { IceFortressStager } from './environments/iceFortress'; +import { SuperBrieFactoryStager } from './environments/superBrieFactory'; const stageModules: IStager[] = [ - new IceFortressStager() + new IceFortressStager(), + new SuperBrieFactoryStager(), ]; export { stageModules } diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index e25ffece..dcc9331e 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -58,7 +58,7 @@ export interface Quests { QuestRiftWhiskerWoods?: any QuestSandDunes?: any QuestSunkenCity?: any - QuestSuperBrieFactory?: any + QuestSuperBrieFactory?: quests.QuestSuperBrieFactory QuestTableOfContents?: quests.QuestTableOfContents QuestTrainStation?: any QuestWinterHunt2021?: any diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index 6cacdc74..de657bc0 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -1,2 +1,3 @@ export * from '@scripts/types/quests/iceFortress'; +export * from '@scripts/types/quests/superBrieFactory'; export * from '@scripts/types/quests/tableOfContents'; diff --git a/src/scripts/types/quests/superBrieFactory.ts b/src/scripts/types/quests/superBrieFactory.ts new file mode 100644 index 00000000..f8a12208 --- /dev/null +++ b/src/scripts/types/quests/superBrieFactory.ts @@ -0,0 +1,15 @@ + +export interface QuestSuperBrieFactory { + factory_atts: FactoryAtts; +} + +interface FactoryAtts { + current_room: RoomType; + boss_warning: boolean | null; +} + +export type RoomType = + | "mixing_room" + | "break_room" + | "pumping_room" + | "quality_assurance_room"; diff --git a/tests/scripts/modules/stages/iceFortress.spec.ts b/tests/scripts/modules/stages/environments/iceFortress.spec.ts similarity index 87% rename from tests/scripts/modules/stages/iceFortress.spec.ts rename to tests/scripts/modules/stages/environments/iceFortress.spec.ts index 7d454ace..fbb7a794 100644 --- a/tests/scripts/modules/stages/iceFortress.spec.ts +++ b/tests/scripts/modules/stages/environments/iceFortress.spec.ts @@ -1,4 +1,4 @@ -import { IceFortressStager } from '@scripts/modules/stages/iceFortress' +import { IceFortressStager } from '@scripts/modules/stages/environments/iceFortress' import { User } from '@scripts/types/hg'; describe('IceFortressStager', () => { From c4a80a095760dfba46e25a822f70087bf363a42a Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Tue, 28 Feb 2023 16:36:16 -0500 Subject: [PATCH 2/2] Add tests for sb factory stager --- .../environments/superBrieFactory.spec.ts | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tests/scripts/modules/stages/environments/superBrieFactory.spec.ts diff --git a/tests/scripts/modules/stages/environments/superBrieFactory.spec.ts b/tests/scripts/modules/stages/environments/superBrieFactory.spec.ts new file mode 100644 index 00000000..80702239 --- /dev/null +++ b/tests/scripts/modules/stages/environments/superBrieFactory.spec.ts @@ -0,0 +1,131 @@ +import { SuperBrieFactoryStager } from "@scripts/modules/stages/environments/superBrieFactory"; +import type { User } from "@scripts/types/hg"; +import type { IntakeMessage } from "@scripts/types/mhct"; +import type { QuestSuperBrieFactory } from "@scripts/types/quests"; + +describe("SuperBrieFactoryStager", () => { + const defaultJournal = {}; + const defaultQuest: QuestSuperBrieFactory = { + factory_atts: { + current_room: "pumping_room", + boss_warning: null, + } + }; + const defaultUser = { + quests: { + QuestSuperBrieFactory: defaultQuest, + }, + } as User; + + it("is for the SUPER|brie+ Factory environment", () => { + const stager = new SuperBrieFactoryStager(); + + expect(stager.environment).toBe("SUPER|brie+ Factory"); + }); + + it("throws when the quest is undefined", () => { + const stager = new SuperBrieFactoryStager(); + const user = changeFactoryQuest(defaultUser, undefined!); + + expect(() => { + stager.addStage({} as any, user, user, defaultJournal); + }).toThrowError("User is in SB+ factory but quest wasn't found."); + }); + + describe("boss", () => { + it("is Boss stage when pre mouse is Vincent", () => { + const stager = new SuperBrieFactoryStager(); + const message = { + mouse: "Vincent, The Magnificent", + } as IntakeMessage; + const preUser = changeFactoryQuest(defaultUser, defaultQuest); + + stager.addStage(message, preUser, defaultUser, defaultJournal); + + expect(message.stage).toBe("Boss"); + }); + + it("is Boss stage when there is boss_warning", () => { + const stager = new SuperBrieFactoryStager(); + const message = {} as IntakeMessage; + const preUser = { + ...defaultUser, + quests: { + QuestSuperBrieFactory: { + factory_atts: { boss_warning: true }, + }, + }, + } as User; + + stager.addStage(message, preUser, defaultUser, defaultJournal); + + expect(message.stage).toBe("Boss"); + }); + }); + + describe('rooms', () => { + it.each([ + { room: "pumping_room", expected: "Pump Room" }, + { room: "mixing_room", expected: "Mixing Room" }, + { room: "break_room", expected: "Break Room" }, + { room: "quality_assurance_room", expected: "QA Room" }, + ])('sets room with Coggy Colby', ({room, expected}) => { + + const stager = new SuperBrieFactoryStager(); + const message = {} as IntakeMessage; + const preUser = { + ...defaultUser, + bait_name: 'Coggy Colby Cheese', + quests: { + QuestSuperBrieFactory: { + factory_atts: { current_room: room }, + }, + }, + } as User; + + stager.addStage(message, preUser, defaultUser, defaultJournal); + expect(message.stage).toBe(expected); + }); + + it('is any room with non-coggy colby', () => { + const stager = new SuperBrieFactoryStager(); + const message = {} as IntakeMessage; + const preUser = { + ...defaultUser, + bait_name: 'Gouda Cheese', + quests: { + QuestSuperBrieFactory: { + factory_atts: { current_room: 'pumping_room' }, + }, + }, + } as User; + + stager.addStage(message, preUser, defaultUser, defaultJournal); + expect(message.stage).toBe('Any Room'); + }) + }); + + describe('other rooms', () => { + it('defaults to Any Room for unsupported room type', () => { + const stager = new SuperBrieFactoryStager(); + const message = {} as IntakeMessage; + const user = { + ...defaultUser, + quests: { + QuestSuperBrieFactory: { + factory_atts: { current_room: 'secret_room' } + } + } + } as unknown as User; + + stager.addStage(message, user, defaultUser, defaultJournal) + + expect(message.stage).toBe('Any Room'); + }) + }); + + function changeFactoryQuest(user: User, quest: QuestSuperBrieFactory): User { + user.quests.QuestSuperBrieFactory = quest; + return user; + } +});