Skip to content

Commit

Permalink
Table of Contents stager (#522)
Browse files Browse the repository at this point in the history
* Add Table of Contents stage tests

* Add Table of Contents stager
  • Loading branch information
hymccord authored Feb 4, 2024
1 parent 5fcb9da commit 59461f2
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,6 @@ import * as detailingFuncs from './modules/details/legacy';
"Iceberg": stagingFuncs.addIcebergStage,
"Seasonal Garden": stagingFuncs.addSeasonalGardenStage,
"Sunken City": stagingFuncs.addSunkenCityStage,
"Table of Contents": stagingFuncs.addTableOfContentsStage,
"Toxic Spill": stagingFuncs.addToxicSpillStage,
"Valour Rift": stagingFuncs.addValourRiftStage,
"Whisker Woods Rift": stagingFuncs.addWhiskerWoodsRiftStage,
Expand Down
23 changes: 23 additions & 0 deletions src/scripts/modules/stages/environments/tableOfContents.ts
Original file line number Diff line number Diff line change
@@ -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 TableOfContentsStager implements IStager {
readonly environment: string = 'Table of Contents';

addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void {
const quest = userPre.quests.QuestTableOfContents;

if (!quest) {
throw new Error('QuestTableOfContents is undefined');
}

if (quest.is_writing) {
message.stage = quest.current_book.volume > 0
? 'Encyclopedia'
: 'Pre-Encyclopedia';
} else {
message.stage = 'Not Writing';
}
}
}
2 changes: 2 additions & 0 deletions src/scripts/modules/stages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {QuesoGeyserStager} from './environments/quesoGeyser';
import {SandDunesStager} from './environments/sandDunes';
import {SlushyShorelineStager} from './environments/slushyShoreline';
import {SuperBrieFactoryStager} from './environments/superBrieFactory';
import {TableOfContentsStager} from './environments/tableOfContents';
import {TwistedGardenStager} from './environments/twistedGarden';
import {ZokorStager} from './environments/zokor';

Expand All @@ -47,6 +48,7 @@ const stageModules: IStager[] = [
new SandDunesStager(),
new SlushyShorelineStager(),
new SuperBrieFactoryStager(),
new TableOfContentsStager(),
new TwistedGardenStager(),
new ZokorStager(),
];
Expand Down
22 changes: 0 additions & 22 deletions src/scripts/modules/stages/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,28 +191,6 @@ export function addFuromaRiftStage(message, user, user_post, hunt) {
}
}

/**
* Set the Table of Contents Stage
* @param {Object <string, any>} message The message to be sent.
* @param {Object <string, any>} user The user state object, when the hunt was invoked (pre-hunt).
* @param {Object <string, any>} user_post The user state object, after the hunt.
* @param {Object <string, any>} hunt The journal entry corresponding to the active hunt.
*/
export function addTableOfContentsStage(message, user, user_post, hunt) {
const quest = user.quests.QuestTableOfContents;
if (quest) {
if (quest.is_writing) {
if (quest.current_book.volume > 0) {
message.stage = 'Encyclopedia';
} else {
message.stage = 'Pre-Encyclopedia';
}
} else {
message.stage = 'Not Writing';
}
}
}

/**
*
* @param {Object <string, any>} message The message to be sent.
Expand Down
72 changes: 72 additions & 0 deletions tests/scripts/modules/stages/environments/tableOfContents.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

import {TableOfContentsStager} from "@scripts/modules/stages/environments/tableOfContents";
import {IStager} from "@scripts/modules/stages/stages.types";
import {User} from "@scripts/types/hg";
import {IntakeMessage} from "@scripts/types/mhct";

describe('Table of Contents stages', () => {
let stager: IStager;

beforeEach(() => {
stager = new TableOfContentsStager();
});

it('should be for the Table of Contents environment', () => {
expect(stager.environment).toBe('Table of Contents');
});

it.each([undefined, null])('should throw when QuestTableOfContents is %p', (quest) => {
const message = {location: {}} as IntakeMessage;
const preUser = {quests: {QuestTableOfContents: quest}} as User;
const postUser = {} as User;
const journal = {};

expect(() => stager.addStage(message, preUser, postUser, journal))
.toThrow('QuestTableOfContents is undefined');
});

it('should set stage to Not Writing if user is not writing', () => {
const message = {} as IntakeMessage;
const preUser = {quests: {QuestTableOfContents: {
is_writing: false,
}}} as User;
const postUser = {} as User;
const journal = {};

stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe('Not Writing');
});

it('should set stage to Pre-Encyclopedia when writing first volume', () => {
const message = {} as IntakeMessage;
const preUser = {quests: {QuestTableOfContents: {
is_writing: true,
current_book: {
volume: 0,
},
}}} as User;
const postUser = {} as User;
const journal = {};

stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe('Pre-Encyclopedia');
});

it('should set stage to Encyclopeda when writing after first volume', () => {
const message = {} as IntakeMessage;
const preUser = {quests: {QuestTableOfContents: {
is_writing: true,
current_book: {
volume: 1,
},
}}} as User;
const postUser = {} as User;
const journal = {};

stager.addStage(message, preUser, postUser, journal);

expect(message.stage).toBe('Encyclopedia');
});
});

0 comments on commit 59461f2

Please sign in to comment.