From fdc6b8e93d0d1577a0baa9e6a5389b2368844d24 Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Fri, 28 Apr 2023 16:14:23 -0400 Subject: [PATCH 1/2] Add Burroughs Rift stage tests --- .../stages/environments/burroughsRift.spec.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/scripts/modules/stages/environments/burroughsRift.spec.ts diff --git a/tests/scripts/modules/stages/environments/burroughsRift.spec.ts b/tests/scripts/modules/stages/environments/burroughsRift.spec.ts new file mode 100644 index 00000000..8c98be23 --- /dev/null +++ b/tests/scripts/modules/stages/environments/burroughsRift.spec.ts @@ -0,0 +1,46 @@ +import {addBurroughsRiftStage} from "@scripts/modules/stages/legacy"; +import {User} from "@scripts/types/hg"; +import {IntakeMessage} from "@scripts/types/mhct"; + +describe('Burroughs Rift stages', () => { + let message: IntakeMessage; + let preUser: User; + let postUser: User; + const journal = {}; + + beforeEach(() => { + message = {} as IntakeMessage; + preUser = {} as User; + postUser = {} as User; + }); + + it.each` + level | expected + ${'tier_0'} | ${'Mist 0'} + ${'tier_1'} | ${'Mist 1-5'} + ${'tier_2'} | ${'Mist 6-18'} + ${'tier_3'} | ${'Mist 19-20'} + `('should set stage to $expected when mist is at $level', ({level, expected}) => { + + preUser.quests = {QuestRiftBurroughs: { + mist_tier: level, + }}; + + addBurroughsRiftStage(message, preUser, postUser, journal); + + expect(message.stage).toBe(expected); + }); + + it('should set location to null when mist level is unknown', () => { + message.location = {id: 0, name: ''}; + preUser.quests = {QuestRiftBurroughs: { + mist_tier: 'tier_42', + }}; + + expect(message.location).not.toBeNull(); + + addBurroughsRiftStage(message, preUser, postUser, journal); + + expect(message.location).toBeNull(); + }); +}); From 0220d554944da642db76c52a27aeb7b1602fb2ef Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Tue, 4 Apr 2023 16:57:55 -0400 Subject: [PATCH 2/2] Add Burroughs Rift stager --- src/scripts/main.js | 1 - .../stages/environments/burroughsRift.ts | 36 +++++++++++++++++++ src/scripts/modules/stages/index.ts | 2 ++ src/scripts/modules/stages/legacy.js | 20 ----------- src/scripts/types/hg.ts | 2 +- src/scripts/types/quests/burroughsRift.ts | 7 ++++ src/scripts/types/quests/index.ts | 1 + .../stages/environments/burroughsRift.spec.ts | 27 +++++++++----- 8 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 src/scripts/modules/stages/environments/burroughsRift.ts create mode 100644 src/scripts/types/quests/burroughsRift.ts diff --git a/src/scripts/main.js b/src/scripts/main.js index 49e4ad5b..4fe60034 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 = { - "Burroughs Rift": stagingFuncs.addBurroughsRiftStage, "Festive Comet": stagingFuncs.addFestiveCometStage, "Frozen Vacant Lot": stagingFuncs.addFestiveCometStage, "Foreword Farm": stagingFuncs.addForewordFarmStage, diff --git a/src/scripts/modules/stages/environments/burroughsRift.ts b/src/scripts/modules/stages/environments/burroughsRift.ts new file mode 100644 index 00000000..18f6f1d7 --- /dev/null +++ b/src/scripts/modules/stages/environments/burroughsRift.ts @@ -0,0 +1,36 @@ +import {type User} from '@scripts/types/hg'; +import {IntakeMessage} from '@scripts/types/mhct'; +import {MistTier, MistTiers} from '@scripts/types/quests'; +import {type IStager} from '../stages.types'; + +export class BurroughsRiftStager implements IStager { + readonly environment: string = 'Burroughs Rift'; + + readonly tierToStage: Record = { + 'tier_0': 'Mist 0', + 'tier_1': 'Mist 1-5', + 'tier_2': 'Mist 6-18', + 'tier_3': 'Mist 19-20', + }; + + /** + * Report the misting state + */ + addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { + const quest = userPre.quests.QuestRiftBurroughs; + + if (!quest) { + throw new Error('QuestRiftBurroughs is undefined'); + } + + if (!this.isValidMistTier(quest.mist_tier)) { + throw new Error('Skipping unknown Burroughs Rift mist state'); + } + + message.stage = this.tierToStage[quest.mist_tier]; + } + + private isValidMistTier(value: unknown): value is MistTier { + return typeof value === 'string' && MistTiers.includes(value as MistTier); + } +} diff --git a/src/scripts/modules/stages/index.ts b/src/scripts/modules/stages/index.ts index 048d78f1..bf9ec4cd 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 {BristleWoodsRiftStager} from './environments/bristleWoodsRift'; +import {BurroughsRiftStager} from './environments/burroughsRift'; import {ClawShotCityStager} from './environments/clawShotCity'; import {CursedCityStager} from './environments/cursedCity'; import {FieryWarpathStager} from './environments/fieryWarpath'; @@ -28,6 +29,7 @@ const stageModules: IStager[] = [ new BalacksCoveStager(), new BountifulBeanstalkStager(), new BristleWoodsRiftStager(), + new BurroughsRiftStager(), new ClawShotCityStager(), new CursedCityStager(), new FieryWarpathStager(), diff --git a/src/scripts/modules/stages/legacy.js b/src/scripts/modules/stages/legacy.js index 5f76b224..e996f4e5 100644 --- a/src/scripts/modules/stages/legacy.js +++ b/src/scripts/modules/stages/legacy.js @@ -246,26 +246,6 @@ export function addToxicSpillStage(message, user, user_post, hunt) { } } -/** - * Report the misting state - * @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 addBurroughsRiftStage(message, user, user_post, hunt) { - const quest = user.quests.QuestRiftBurroughs; - message.stage = (({ - "tier_0": "Mist 0", - "tier_1": "Mist 1-5", - "tier_2": "Mist 6-18", - "tier_3": "Mist 19-20", - })[quest.mist_tier]); - if (!message.stage) { - message.location = null; - } -} - /** * Report on the unique minigames in each sub-location. Reject hunts for which the train * moved / updated / departed, as the hunt stage is ambiguous. diff --git a/src/scripts/types/hg.ts b/src/scripts/types/hg.ts index 5c325051..bbed5eb9 100644 --- a/src/scripts/types/hg.ts +++ b/src/scripts/types/hg.ts @@ -59,7 +59,7 @@ export interface Quests { QuestQuesoGeyser?: quests.QuestQuesoGeyser QuestRelicHunter?: unknown QuestRiftBristleWoods?: quests.QuestRiftBristleWoods - QuestRiftBurroughs?: unknown + QuestRiftBurroughs?: quests.QuestRiftBurroughs QuestRiftFuroma?: unknown QuestRiftWhiskerWoods?: unknown QuestSandDunes?: quests.QuestSandDunes diff --git a/src/scripts/types/quests/burroughsRift.ts b/src/scripts/types/quests/burroughsRift.ts new file mode 100644 index 00000000..9ef9726c --- /dev/null +++ b/src/scripts/types/quests/burroughsRift.ts @@ -0,0 +1,7 @@ +export interface QuestRiftBurroughs { + mist_tier: string // MistTier +} + +export const MistTiers = ['tier_0', 'tier_1', 'tier_2', 'tier_3'] as const; + +export type MistTier = typeof MistTiers[number]; diff --git a/src/scripts/types/quests/index.ts b/src/scripts/types/quests/index.ts index c0d0773c..2d3bbc65 100644 --- a/src/scripts/types/quests/index.ts +++ b/src/scripts/types/quests/index.ts @@ -1,6 +1,7 @@ export * from '@scripts/types/quests/balacksCove'; export * from '@scripts/types/quests/bountifulBeanstalk'; export * from '@scripts/types/quests/bristleWoodsRift'; +export * from '@scripts/types/quests/burroughsRift'; 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/burroughsRift.spec.ts b/tests/scripts/modules/stages/environments/burroughsRift.spec.ts index 8c98be23..dab8f8db 100644 --- a/tests/scripts/modules/stages/environments/burroughsRift.spec.ts +++ b/tests/scripts/modules/stages/environments/burroughsRift.spec.ts @@ -1,19 +1,33 @@ -import {addBurroughsRiftStage} from "@scripts/modules/stages/legacy"; +import {BurroughsRiftStager} from "@scripts/modules/stages/environments/burroughsRift"; +import {IStager} from "@scripts/modules/stages/stages.types"; import {User} from "@scripts/types/hg"; import {IntakeMessage} from "@scripts/types/mhct"; describe('Burroughs Rift stages', () => { + let stager: IStager; let message: IntakeMessage; let preUser: User; let postUser: User; const journal = {}; beforeEach(() => { + stager = new BurroughsRiftStager(); message = {} as IntakeMessage; preUser = {} as User; postUser = {} as User; }); + it('should be for the Burroughs Rift environment', () => { + expect(stager.environment).toBe('Burroughs Rift'); + }); + + it('should throw when QuestRiftBurroughs is undefined', () => { + preUser.quests = {}; + + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('QuestRiftBurroughs is undefined'); + }); + it.each` level | expected ${'tier_0'} | ${'Mist 0'} @@ -26,21 +40,18 @@ describe('Burroughs Rift stages', () => { mist_tier: level, }}; - addBurroughsRiftStage(message, preUser, postUser, journal); + stager.addStage(message, preUser, postUser, journal); expect(message.stage).toBe(expected); }); - it('should set location to null when mist level is unknown', () => { + it('should throw when mist level is unknown', () => { message.location = {id: 0, name: ''}; preUser.quests = {QuestRiftBurroughs: { mist_tier: 'tier_42', }}; - expect(message.location).not.toBeNull(); - - addBurroughsRiftStage(message, preUser, postUser, journal); - - expect(message.location).toBeNull(); + expect(() => stager.addStage(message, preUser, postUser, journal)) + .toThrow('Skipping unknown Burroughs Rift mist state'); }); });