Skip to content

Commit

Permalink
testing found bugs!
Browse files Browse the repository at this point in the history
  • Loading branch information
AardWolf committed Dec 17, 2023
1 parent 79ab4c8 commit e378ccc
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
117 changes: 117 additions & 0 deletions tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts
Original file line number Diff line number Diff line change
@@ -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 },

Check failure on line 35 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

There should be no space after '{'

Check failure on line 35 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

There should be no space after '{'

Check failure on line 35 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

There should be no space before '}'
cannons: {

Check failure on line 36 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Expected indentation of 16 spaces but found 48
charm_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" },

Check failure on line 37 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Expected indentation of 20 spaces but found 52

Check failure on line 37 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

There should be no space after '{'

Check failure on line 37 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

There should be no space before '}'
cinnamon_cannon: { is_enabled: null, is_active: null, just_fired: null, state: "disabled" },

Check failure on line 38 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Expected indentation of 20 spaces but found 52

Check failure on line 38 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

There should be no space after '{'

Check failure on line 38 in tests/scripts/hunt-filter/exemptions/environments/iceFortress.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

There should be no space before '}'
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;
}
});

0 comments on commit e378ccc

Please sign in to comment.