-
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.
Migrate to Queso Geyser stager (#518)
- Loading branch information
Showing
8 changed files
with
119 additions
and
20 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,37 @@ | ||
import {type User} from '@scripts/types/hg'; | ||
import {IntakeMessage} from '@scripts/types/mhct'; | ||
import {QuesoGeyserState, QuesoGeyserStates} from '@scripts/types/quests/quesoGeyser'; | ||
import {type IStager} from '../stages.types'; | ||
|
||
export class QuesoGeyserStager implements IStager { | ||
readonly environment: string = 'Queso Geyser'; | ||
|
||
/** | ||
* Report the state of corks and eruptions | ||
*/ | ||
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { | ||
const quest = userPre.quests.QuestQuesoGeyser; | ||
|
||
if (!quest) { | ||
throw new Error('QuestQuesoGeyser is undefined'); | ||
} | ||
|
||
if (!this.isValidState(quest.state)) { | ||
throw new Error('Skipping hunt due to unknown Queso Geyser state'); | ||
} | ||
|
||
const state = quest.state; | ||
if (state === "collecting" || state === "claim") { | ||
message.stage = "Cork Collecting"; | ||
} else if (state === "corked") { | ||
message.stage = "Pressure Building"; | ||
} else if (state === "eruption") { | ||
// Tiny/Small/Medium/Large/Epic Eruption | ||
message.stage = quest.state_name; | ||
} | ||
} | ||
|
||
private isValidState(value: unknown): value is QuesoGeyserState { | ||
return typeof value === 'string' && QuesoGeyserStates.includes(value as QuesoGeyserState); | ||
} | ||
} |
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
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,8 @@ | ||
export interface QuestQuesoGeyser { | ||
state: string // QuesoGeyserState | ||
state_name: string; | ||
} | ||
|
||
export const QuesoGeyserStates = [ 'collecting', 'corked', 'eruption', 'claim' ] as const; | ||
|
||
export type QuesoGeyserState = typeof QuesoGeyserStates[number]; |
70 changes: 70 additions & 0 deletions
70
tests/scripts/modules/stages/environments/quesoGeyser.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,70 @@ | ||
import {QuesoGeyserStager} from "@scripts/modules/stages/environments/quesoGeyser"; | ||
import {IStager} from "@scripts/modules/stages/stages.types"; | ||
import {User} from "@scripts/types/hg"; | ||
import {IntakeMessage} from "@scripts/types/mhct"; | ||
|
||
describe('Queso Geyser stages', () => { | ||
let stager: IStager; | ||
let message: IntakeMessage; | ||
let preUser: User; | ||
let postUser: User; | ||
const journal = {}; | ||
|
||
beforeEach(() => { | ||
stager = new QuesoGeyserStager(); | ||
message = {} as IntakeMessage; | ||
preUser = {quests: { | ||
QuestQuesoGeyser: getDefaultQuest(), | ||
}} as User; | ||
postUser = {} as User; | ||
}); | ||
|
||
it('should be for the Queso Geyser environment', () => { | ||
expect(stager.environment).toBe('Queso Geyser'); | ||
}); | ||
|
||
it('should throw when QuestQuesoGeyser is undefined', () => { | ||
preUser.quests.QuestQuesoGeyser = undefined; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('QuestQuesoGeyser is undefined'); | ||
}); | ||
|
||
it.each` | ||
state | expected | ||
${'collecting'} | ${'Cork Collecting'} | ||
${'claim'} | ${'Cork Collecting'} | ||
${'corked'} | ${'Pressure Building'} | ||
`('should set stage to $expected when in $state state', ({state, expected}) => { | ||
preUser.quests.QuestQuesoGeyser!.state = state; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe(expected); | ||
}); | ||
|
||
it.each( | ||
['Tiny', 'Small', 'Medium', 'Large', 'Epic'] | ||
)('should set stage to state name %p when in a %p Eruption ', (name) => { | ||
preUser.quests.QuestQuesoGeyser!.state = 'eruption'; | ||
preUser.quests.QuestQuesoGeyser!.state_name = `${name} Eruption`; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe(`${name} Eruption`); | ||
}); | ||
|
||
it('should throw when state is unknown', () => { | ||
preUser.quests.QuestQuesoGeyser!.state = 'guaranteed_rib_mode'; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('Skipping hunt due to unknown Queso Geyser state'); | ||
}); | ||
|
||
function getDefaultQuest() { | ||
return { | ||
state: '', | ||
state_name: '', | ||
}; | ||
} | ||
}); |