diff --git a/.eslintrc.js b/.eslintrc.js index 287c5f21..17ef949f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -68,5 +68,13 @@ module.exports = { }, plugins: ['jest'], }, + { + files: [ + '**/*.{test,spec}.ts', + ], + rules: { + '@typescript-eslint/no-non-null-assertion': 'off', + }, + }, ], }; diff --git a/src/scripts/main.js b/src/scripts/main.js index b75959bf..5fe492c7 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -1174,7 +1174,6 @@ import * as detailingFuncs from './modules/details/legacy'; /** @type {Object } */ const location_stage_lookup = { - "Bristle Woods Rift": stagingFuncs.addBristleWoodsRiftStage, "Burroughs Rift": stagingFuncs.addBurroughsRiftStage, "Festive Comet": stagingFuncs.addFestiveCometStage, "Frozen Vacant Lot": stagingFuncs.addFestiveCometStage, diff --git a/src/scripts/modules/stages/environments/bristleWoodsRift.ts b/src/scripts/modules/stages/environments/bristleWoodsRift.ts new file mode 100644 index 00000000..aa39586b --- /dev/null +++ b/src/scripts/modules/stages/environments/bristleWoodsRift.ts @@ -0,0 +1,23 @@ +import {type User} from '@scripts/types/hg'; +import {type IntakeMessage} from '@scripts/types/mhct'; +import {type IStager} from '../stages.types'; + +export class BristleWoodsRiftStager implements IStager { + readonly environment: string = 'Bristle Woods Rift'; + + /** + * Report the current chamber name. + */ + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + const quest = userPre.quests.QuestRiftBristleWoods; + + if (!quest) { + throw new Error('QuestRiftBristleWoods is undefined'); + } + + message.stage = quest.chamber_name; + if (message.stage === "Rift Acolyte Tower") { + message.stage = "Entrance"; + } + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index 47bfda01..0363b2e1 100644 --- a/src/scripts/modules/stages/index.ts +++ b/src/scripts/modules/stages/index.ts @@ -1,6 +1,7 @@ import {type IStager} from './stages.types'; import {BalacksCoveStager} from './environments/balacksCove'; import {BountifulBeanstalkStager} from './environments/bountifulBeanstalk'; +import {BristleWoodsRiftStager} from './environments/bristleWoodsRift'; import {ClawShotCityStager} from './environments/clawShotCity'; import {CursedCityStager} from './environments/cursedCity'; import {FieryWarpathStager} from './environments/fieryWarpath'; @@ -23,6 +24,7 @@ import {TwistedGardenStager} from './environments/twistedGarden'; const stageModules: IStager[] = [ new BalacksCoveStager(), new BountifulBeanstalkStager(), + new BristleWoodsRiftStager(), new ClawShotCityStager(), new CursedCityStager(), new FieryWarpathStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index 0bc64145..43aed050 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -423,21 +423,6 @@ export function addFortRoxStage(message, user, user_post, hunt) { } } -/** - * Report the current chamber name. - * @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 addBristleWoodsRiftStage(message, user, user_post, hunt) { - message.stage = user.quests.QuestRiftBristleWoods.chamber_name; - if (message.stage === "Rift Acolyte Tower") { - message.stage = "Entrance"; - } -} - - /** * Report the state of corks and eruptions * @param {Object } message The message to be sent. diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index ef483bc8..46909eff 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -58,7 +58,7 @@ export interface Quests { QuestPollutionOutbreak?: unknown QuestQuesoGeyser?: unknown QuestRelicHunter?: unknown - QuestRiftBristleWoods?: unknown + QuestRiftBristleWoods?: quests.QuestRiftBristleWoods QuestRiftBurroughs?: unknown QuestRiftFuroma?: unknown QuestRiftWhiskerWoods?: unknown diff --git a/src/scripts/types/quests/bristleWoodsRift.ts b/src/scripts/types/quests/bristleWoodsRift.ts new file mode 100644 index 00000000..8a331fd2 --- /dev/null +++ b/src/scripts/types/quests/bristleWoodsRift.ts @@ -0,0 +1,3 @@ +export interface QuestRiftBristleWoods { + chamber_name: string +} diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index 3206b947..04d06a2d 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -1,5 +1,6 @@ export * from '@scripts/types/quests/balacksCove'; export * from '@scripts/types/quests/bountifulBeanstalk'; +export * from '@scripts/types/quests/bristleWoodsRift'; export * from '@scripts/types/quests/clawShotCity'; export * from '@scripts/types/quests/floatingIslands'; export * from '@scripts/types/quests/forbiddenGrove'; diff --git a/tests/scripts/modules/stages/environments/bristleWoodsRift.spec.ts b/tests/scripts/modules/stages/environments/bristleWoodsRift.spec.ts new file mode 100644 index 00000000..17255404 --- /dev/null +++ b/tests/scripts/modules/stages/environments/bristleWoodsRift.spec.ts @@ -0,0 +1,67 @@ +import {BristleWoodsRiftStager} from "@scripts/modules/stages/environments/bristleWoodsRift"; +import {IStager} from "@scripts/modules/stages/stages.types"; +import {User} from "@scripts/types/hg"; +import {IntakeMessage} from "@scripts/types/mhct"; +import {QuestRiftBristleWoods} from "@scripts/types/quests"; + +describe('Bristle Woods Rift stages', () => { + let stager: IStager; + let message: IntakeMessage; + let preUser: User; + let postUser: User; + const journal = {}; + + const ChamberNames = [ + "Acolyte", + "Ancient Lab", + "Frozen Alcove", + "Furnace Room", + "Gearworks", + "Guard Barracks", + "Hidden Treasury", + "Ingress", + "Lucky Tower", + "Pursuer Mousoleum", + "Runic Laboratory", + "Rift Acolyte Tower", // Entrance + "Security", + "Timewarp", + ]; + + beforeEach(() => { + stager = new BristleWoodsRiftStager(); + message = {} as IntakeMessage; + preUser = {quests: { + QuestRiftBristleWoods: getDefaultQuest(), + }} as User; + postUser = {quests: { + QuestRiftBristleWoods: getDefaultQuest(), + }} as User; + }); + + it('should be for the Bristle Woods Rift environment', () => { + expect(stager.environment).toBe('Bristle Woods Rift'); + }); + + it('should throw when QuestRiftBristleWoods is undefined', () => { + preUser.quests.QuestRiftBristleWoods = undefined; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestRiftBristleWoods is undefined'); + }); + + it.each(ChamberNames)('should set stage name to chamber name', (chamberName) => { + preUser.quests.QuestRiftBristleWoods!.chamber_name = chamberName; + + stager.addStage(message, preUser, postUser, journal); + + const expected = chamberName === "Rift Acolyte Tower" ? "Entrance" : chamberName; + expect(message.stage).toBe(expected); + }); + + function getDefaultQuest(): QuestRiftBristleWoods { + return { + chamber_name: '', + }; + } +});