-
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.
Merge pull request #499 from hymccord/fw-stage
Fiery Warpath stager
- Loading branch information
Showing
6 changed files
with
88 additions
and
11 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,25 @@ | ||
import type {FieryWarpathViewingAttributes, ViewingAttributes, User} from '@scripts/types/hg'; | ||
import {type IntakeMessage} from '@scripts/types/mhct'; | ||
import {type IStager} from '../stages.types'; | ||
|
||
export class FieryWarpathStager implements IStager { | ||
readonly environment: string = 'Fiery Warpath'; | ||
|
||
addStage(message: IntakeMessage, userPre: User, userPost: User, journal: unknown): void { | ||
|
||
const viewing_atts = userPre.viewing_atts; | ||
if (!this.isWarpath(viewing_atts)) { | ||
throw new Error('Fiery Warpath viewing attributes are undefined'); | ||
} | ||
|
||
const wave = viewing_atts.desert_warpath.wave; | ||
message.stage = (wave === "portal") ? "Portal" : `Wave ${wave}`; | ||
} | ||
|
||
/** | ||
* Check if the given viewing attributes narrows down to the fiery warpath one | ||
*/ | ||
private isWarpath(object: ViewingAttributes): object is FieryWarpathViewingAttributes { | ||
return (object as FieryWarpathViewingAttributes).desert_warpath != null; | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
tests/scripts/modules/stages/environments/fieryWarpath.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,52 @@ | ||
import {FieryWarpathStager} from "@scripts/modules/stages/environments/fieryWarpath"; | ||
import {User} from "@scripts/types/hg"; | ||
import {IntakeMessage} from "@scripts/types/mhct"; | ||
|
||
describe('Fiery Warpath stages', () => { | ||
it('should be for the "Fiery Warpath" environment', () => { | ||
const stager = new FieryWarpathStager(); | ||
expect(stager.environment).toBe('Fiery Warpath'); | ||
}); | ||
|
||
it('sets stage to "Portal" when wave is portal', () => { | ||
const stager = new FieryWarpathStager(); | ||
|
||
const message = {} as IntakeMessage; | ||
const preUser = {viewing_atts:{desert_warpath: { | ||
wave: 'portal', | ||
}}} as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe('Portal'); | ||
}); | ||
|
||
it('sets stage to "Wave #" when wave is numbered waved', () => { | ||
const stager = new FieryWarpathStager(); | ||
|
||
const message = {} as IntakeMessage; | ||
const preUser = {viewing_atts:{desert_warpath: { | ||
wave: 4, | ||
}}} as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
stager.addStage(message, preUser, postUser, journal); | ||
|
||
expect(message.stage).toBe('Wave 4'); | ||
}); | ||
|
||
it.each([undefined, null])('throws when "desert_warpath" viewer atts are null or undefined', (state) => { | ||
const stager = new FieryWarpathStager(); | ||
|
||
const message = {} as IntakeMessage; | ||
const preUser = {viewing_atts:{desert_warpath: state}} as unknown as User; | ||
const postUser = {} as User; | ||
const journal = {}; | ||
|
||
expect(() => stager.addStage(message, preUser, postUser, journal)) | ||
.toThrow('Fiery Warpath viewing attributes are undefined'); | ||
}); | ||
}); |