-
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 Iceberg stage tests * Add Iceberg stager * Import iceberg types from appropriate quest file
- Loading branch information
Showing
6 changed files
with
107 additions
and
32 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
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,41 @@ | ||
import {type User} from '@scripts/types/hg'; | ||
import {type IntakeMessage} from '@scripts/types/mhct'; | ||
import {IcebergPhases, type IcebergPhase} from '@scripts/types/quests'; | ||
import {type IStager} from '../stages.types'; | ||
|
||
export class IcebergStager implements IStager { | ||
readonly environment: string = 'Iceberg'; | ||
|
||
readonly phaseToStage: Record<IcebergPhase, string> = { | ||
'Treacherous Tunnels': '0-300ft', | ||
'Brutal Bulwark': '301-600ft', | ||
'Bombing Run': '601-1600ft', | ||
'The Mad Depths': '1601-1800ft', | ||
'Icewing\'s Lair': '1800ft', | ||
'Hidden Depths': '1801-2000ft', | ||
'The Deep Lair': '2000ft', | ||
'General': 'Generals', | ||
}; | ||
|
||
/** | ||
* Report the current distance / obstacle. | ||
* TODO: Stage / hunt details for first & second icewing hunting? | ||
*/ | ||
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { | ||
const quest = userPre.quests.QuestIceberg; | ||
|
||
if (!quest) { | ||
throw new Error('QuestIceberg is undefined'); | ||
} | ||
|
||
if (!this.isIcebergPhase(quest.current_phase)) { | ||
throw new Error('Skipping unknown Iceberg stage'); | ||
} | ||
|
||
message.stage = this.phaseToStage[quest.current_phase]; | ||
} | ||
|
||
private isIcebergPhase(value: string): value is IcebergPhase { | ||
return IcebergPhases.includes(value as IcebergPhase); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {IcebergStager} from "@scripts/modules/stages/environments/iceberg"; | ||
import {User} from "@scripts/types/hg"; | ||
import {IntakeMessage} from "@scripts/types/mhct"; | ||
|
||
describe('Iceberg Stages', () => { | ||
it('should be for the "Iceberg" environment', () => { | ||
const stager = new IcebergStager(); | ||
expect(stager.environment).toBe('Iceberg'); | ||
}); | ||
|
||
it.each` | ||
phase | expected | ||
${'Treacherous Tunnels'} | ${'0-300ft'} | ||
${'Brutal Bulwark'} | ${'301-600ft'} | ||
${'Bombing Run'} | ${'601-1600ft'} | ||
${'The Mad Depths'} | ${'1601-1800ft'} | ||
${'Icewing\'s Lair'} | ${'1800ft'} | ||
${'Hidden Depths'} | ${'1801-2000ft'} | ||
${'The Deep Lair'} | ${'2000ft'} | ||
${'General'} | ${'Generals'} | ||
`('should set stage to $expected when in the $phase phase', ({expected, phase}) => { | ||
const stager = new IcebergStager(); | ||
const message = {} as IntakeMessage; | ||
const preUser = {quests: {QuestIceberg: { | ||
current_phase: phase, | ||
}}} as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe(expected); | ||
}); | ||
|
||
it('should should throw on unknown phase', () => { | ||
const stager = new IcebergStager(); | ||
const message = {location: {}} as IntakeMessage; | ||
const preUser = {quests: {QuestIceberg: { | ||
current_phase: 'Aard\'s Lair', | ||
}}} as unknown as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('Skipping unknown Iceberg stage'); | ||
}); | ||
|
||
it.each([undefined, null])('should throw when QuestIceberg is %p', (state) => { | ||
const stager = new IcebergStager(); | ||
const message = {location: {}} as IntakeMessage; | ||
const preUser = {quests: {QuestIceberg: state}} as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('QuestIceberg is undefined'); | ||
}); | ||
}); |