From e378ccc7d8b9519c66accf121289029a83ef08cb Mon Sep 17 00:00:00 2001 From: Rob Wilson Date: Sun, 17 Dec 2023 17:07:50 -0500 Subject: [PATCH] testing found bugs! --- .../exemptions/environments/iceFortress.ts | 8 +- .../environments/iceFortress.spec.ts | 117 ++++++++++++++++++ 2 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts diff --git a/src/scripts/hunt-filter/exemptions/environments/iceFortress.ts b/src/scripts/hunt-filter/exemptions/environments/iceFortress.ts index 16b0ce82..7da043e8 100644 --- a/src/scripts/hunt-filter/exemptions/environments/iceFortress.ts +++ b/src/scripts/hunt-filter/exemptions/environments/iceFortress.ts @@ -9,15 +9,15 @@ class IceFortressExemption implements IMessageExemption { post: IntakeMessage ): (keyof IntakeMessage)[] | null { if ( - pre.stage === "Barrier Down" && - post.stage === "Barrier Up" && + pre.stage === "Shield Down" && + post.stage === "Shield Up" && pre.mouse === "Frost King" ) { return ["stage"]; } else if ( - pre.stage === "Barrier Up" && - post.stage === "Barrier Down" + pre.stage === "Shield Up" && + post.stage === "Shield Down" ) { // Possibly we could check things like what the old barrier level was but this should be fine // This is the hunt that led to the destruction of the barrier diff --git a/tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts b/tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts new file mode 100644 index 00000000..e1c9a25b --- /dev/null +++ b/tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts @@ -0,0 +1,117 @@ +import {IntakeRejectionEngine} from '@scripts/hunt-filter/engine'; +import {IceFortressStager} from '@scripts/modules/stages/environments/iceFortress'; +import {User} from '@scripts/types/hg'; +import {IntakeMessage} from '@scripts/types/mhct'; +import {LoggerService} from '@scripts/util/logger'; +import {getDefaultIntakeMessage, getDefaultUser} from '@tests/scripts/hunt-filter/common'; + +describe('Ice Fortress exemptions', () => { + let logger: LoggerService; + let stager: IceFortressStager; + let target: IntakeRejectionEngine; + + beforeEach(() => { + logger = {} as LoggerService; + stager = new IceFortressStager(); + target = new IntakeRejectionEngine(logger); + + logger.debug = jest.fn(); + }); + + describe('validateMessage', () => { + let preUser: User; + let postUser: User; + let preMessage: IntakeMessage; + let postMessage: IntakeMessage; + + beforeEach(() => { + preUser = {...getDefaultUser(), ...getIceFortressUser()}; + postUser = {...getDefaultUser(), ...getIceFortressUser()}; + preMessage = {...getDefaultIntakeMessage()}; + postMessage = {...getDefaultIntakeMessage()}; + }); + + it('should accept when no transitions', () => { + preUser.quests.QuestIceFortress = { shield : { is_broken: false }, + cannons: { + charm_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + cinnamon_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + snow_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + } + }; + preUser.quests.QuestIceFortress = { shield : { is_broken: false }, + cannons: { + charm_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + cinnamon_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + snow_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + } + }; + calculateStage(); + + const valid = target.validateMessage(preMessage, postMessage); + + expect(valid).toBe(true); + }); + + it('should accept transtion on breaking the shield', () => { + preUser.quests.QuestIceFortress = { shield : { is_broken: false }, + cannons: { + charm_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + cinnamon_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + snow_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + } + }; + postUser.quests.QuestIceFortress = { shield : { is_broken: true }, + cannons: { + charm_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + cinnamon_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + snow_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + } + }; + calculateStage(); + + const valid = target.validateMessage(preMessage, postMessage); + + expect(valid).toBe(true); + }); + + it('should accept transtion on catching Frost King', () => { + preUser.quests.QuestIceFortress = { shield : { is_broken: true }, + cannons: { + charm_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + cinnamon_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + snow_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + } + }; + postUser.quests.QuestIceFortress = { shield : { is_broken: false }, + cannons: { + charm_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + cinnamon_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + snow_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" }, + } + }; + preMessage.mouse = postMessage.mouse = 'Frost King'; + calculateStage(); + + const valid = target.validateMessage(preMessage, postMessage); + + expect(valid).toBe(true); + }); + /** Sets the pre and post message stage based on current pre and post user */ + function calculateStage() { + stager.addStage(preMessage, preUser, {} as User, {}); + stager.addStage(postMessage, postUser, {} as User, {}); + } + }); + + function getIceFortressUser(): User { + return { + environment_name: 'Ice Fortress', + quests: { + QuestIceFortress: { + shield: { is_broken: false } + }, + }, + } as User; + } +});