-
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 Burroughs Rift stage tests * Add Burroughs Rift stager
- Loading branch information
Showing
8 changed files
with
104 additions
and
22 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,36 @@ | ||
import {type User} from '@scripts/types/hg'; | ||
import {IntakeMessage} from '@scripts/types/mhct'; | ||
import {MistTier, MistTiers} from '@scripts/types/quests'; | ||
import {type IStager} from '../stages.types'; | ||
|
||
export class BurroughsRiftStager implements IStager { | ||
readonly environment: string = 'Burroughs Rift'; | ||
|
||
readonly tierToStage: Record<MistTier, string> = { | ||
'tier_0': 'Mist 0', | ||
'tier_1': 'Mist 1-5', | ||
'tier_2': 'Mist 6-18', | ||
'tier_3': 'Mist 19-20', | ||
}; | ||
|
||
/** | ||
* Report the misting state | ||
*/ | ||
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { | ||
const quest = userPre.quests.QuestRiftBurroughs; | ||
|
||
if (!quest) { | ||
throw new Error('QuestRiftBurroughs is undefined'); | ||
} | ||
|
||
if (!this.isValidMistTier(quest.mist_tier)) { | ||
throw new Error('Skipping unknown Burroughs Rift mist state'); | ||
} | ||
|
||
message.stage = this.tierToStage[quest.mist_tier]; | ||
} | ||
|
||
private isValidMistTier(value: unknown): value is MistTier { | ||
return typeof value === 'string' && MistTiers.includes(value as MistTier); | ||
} | ||
} |
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,7 @@ | ||
export interface QuestRiftBurroughs { | ||
mist_tier: string // MistTier | ||
} | ||
|
||
export const MistTiers = ['tier_0', 'tier_1', 'tier_2', 'tier_3'] as const; | ||
|
||
export type MistTier = typeof MistTiers[number]; |
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
57 changes: 57 additions & 0 deletions
57
tests/scripts/modules/stages/environments/burroughsRift.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,57 @@ | ||
import {BurroughsRiftStager} from "@scripts/modules/stages/environments/burroughsRift"; | ||
import {IStager} from "@scripts/modules/stages/stages.types"; | ||
import {User} from "@scripts/types/hg"; | ||
import {IntakeMessage} from "@scripts/types/mhct"; | ||
|
||
describe('Burroughs Rift stages', () => { | ||
let stager: IStager; | ||
let message: IntakeMessage; | ||
let preUser: User; | ||
let postUser: User; | ||
const journal = {}; | ||
|
||
beforeEach(() => { | ||
stager = new BurroughsRiftStager(); | ||
message = {} as IntakeMessage; | ||
preUser = {} as User; | ||
postUser = {} as User; | ||
}); | ||
|
||
it('should be for the Burroughs Rift environment', () => { | ||
expect(stager.environment).toBe('Burroughs Rift'); | ||
}); | ||
|
||
it('should throw when QuestRiftBurroughs is undefined', () => { | ||
preUser.quests = {}; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('QuestRiftBurroughs is undefined'); | ||
}); | ||
|
||
it.each` | ||
level | expected | ||
${'tier_0'} | ${'Mist 0'} | ||
${'tier_1'} | ${'Mist 1-5'} | ||
${'tier_2'} | ${'Mist 6-18'} | ||
${'tier_3'} | ${'Mist 19-20'} | ||
`('should set stage to $expected when mist is at $level', ({level, expected}) => { | ||
|
||
preUser.quests = {QuestRiftBurroughs: { | ||
mist_tier: level, | ||
}}; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe(expected); | ||
}); | ||
|
||
it('should throw when mist level is unknown', () => { | ||
message.location = {id: 0, name: ''}; | ||
preUser.quests = {QuestRiftBurroughs: { | ||
mist_tier: 'tier_42', | ||
}}; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('Skipping unknown Burroughs Rift mist state'); | ||
}); | ||
}); |