-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Table of Contents stage tests * Add Table of Contents stager
- Loading branch information
Showing
5 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/scripts/modules/stages/environments/tableOfContents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/scripts/modules/stages/environments/tableOfContents.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |