Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Halloween detailer to track boon #482

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/scripts/modules/details/global/halloween.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type {JournalMarkup, User} from '@scripts/types/hg';
import type {IDetailer} from '../details.types';
import type {IntakeMessage} from '@scripts/types/mhct';

export class HalloweenDetailer implements IDetailer {
/**
* Record if the user has boon active.
*/
addDetails(message: IntakeMessage, userPre: User, userPost: User, journal: JournalMarkup): HalloweenDetails | undefined {
const quest = userPre.quests.QuestHalloweenBoilingCauldron;
if (quest?.reward_track.is_complete) {
return {
has_baba_gaga_boon: true,
};
}
}

}

/**
* Type describing the structure of Halloween details added to message for intake
*/
export interface HalloweenDetails {
has_baba_gaga_boon: boolean;
}
2 changes: 2 additions & 0 deletions src/scripts/modules/details/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {IDetailer, IEnvironmentDetailer} from './details.types';
import {IceFortressDetailer} from './environments/iceFortress';
import {HalloweenDetailer} from './global/halloween';
import {SpringEggHuntDetailer} from './global/springEggHunt';

// Detailer for specific location
Expand All @@ -9,6 +10,7 @@ const environmentDetailerModules: IEnvironmentDetailer[] = [

// Detailers that don't match on location (LNY, Halloween)
const globalDetailerModules: IDetailer[] = [
new HalloweenDetailer(),
new SpringEggHuntDetailer(),
];

Expand Down
1 change: 1 addition & 0 deletions src/scripts/types/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface Quests {
QuestForewordFarm?: unknown
QuestFortRox?: unknown
QuestHarbour?: quests.QuestHarbour
QuestHalloweenBoilingCauldron?: quests.QuestHalloweenBoilingCauldron
QuestIceberg?: quests.QuestIceberg;
QuestIceFortress?: quests.QuestIceFortress;
QuestLabyrinth?: unknown
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/types/quests/halloween.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export interface QuestHalloweenBoilingCauldron {
reward_track: {
is_complete: true | null;
}
}
1 change: 1 addition & 0 deletions src/scripts/types/quests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from '@scripts/types/quests/bountifulBeanstalk';
export * from '@scripts/types/quests/clawShotCity';
export * from '@scripts/types/quests/floatingIslands';
export * from '@scripts/types/quests/forbiddenGrove';
export * from '@scripts/types/quests/halloween';
export * from '@scripts/types/quests/harbour';
export * from '@scripts/types/quests/iceberg';
export * from '@scripts/types/quests/iceFortress';
Expand Down
61 changes: 61 additions & 0 deletions tests/scripts/modules/details/global/halloween.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {HalloweenDetailer, type HalloweenDetails} from '@scripts/modules/details/global/halloween';
import {type User} from '@scripts/types/hg';
import {type IntakeMessage} from '@scripts/types/mhct';
import {type QuestHalloweenBoilingCauldron} from '@scripts/types/quests';

describe('HalloweenDetailer', () => {
describe('getDetails', () => {
it('returns undefined when quest is undefined', () => {
const detailer = new HalloweenDetailer();
const message = {} as IntakeMessage;
const user: User = {
quests: {},
} as User;

expect(detailer.addDetails(message, user, user, null!)).toBe(undefined);
});

it('adds expected details when Halloween quest is active and reward track is complete', () => {
const detailer = new HalloweenDetailer();
const message = {} as IntakeMessage;
const postUser = {} as User;
const preQuest: QuestHalloweenBoilingCauldron = getDefaultQuest();
preQuest.reward_track.is_complete = true;

const preUser: User = {
quests: {
QuestHalloweenBoilingCauldron: preQuest,
},
} as User;

const expected: HalloweenDetails = {
has_baba_gaga_boon: true,
};

expect(detailer.addDetails(message, preUser, postUser, null!)).toStrictEqual(expected);
});

it('does not add details when Halloween quest is active and reward track is incomplete', () => {
const detailer = new HalloweenDetailer();
const message = {} as IntakeMessage;
const postUser = {} as User;
const preQuest: QuestHalloweenBoilingCauldron = getDefaultQuest();

const preUser: User = {
quests: {
QuestHalloweenBoilingCauldron: preQuest,
},
} as User;

expect(detailer.addDetails(message, preUser, postUser, null!)).toStrictEqual(undefined);
});
});

function getDefaultQuest(): QuestHalloweenBoilingCauldron {
return {
reward_track: {
is_complete: null,
},
};
}
});