Skip to content

Commit

Permalink
test(acceptance): acceptances tests for raven (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Aug 31, 2023
1 parent df6c976 commit 0e29af5
Show file tree
Hide file tree
Showing 10 changed files with 14,795 additions and 14,753 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ export class GameHistoryRecordService {
newGame: Game,
gameHistoryRecordToInsert: GameHistoryRecordToInsert,
): GameHistoryRecordPlayVoting {
const votes = gameHistoryRecordToInsert.play.votes ?? [];
const nominatedPlayers = this.gamePlayVoteService.getNominatedPlayers(votes, baseGame);
const nominatedPlayers = this.gamePlayVoteService.getNominatedPlayers(gameHistoryRecordToInsert.play.votes, baseGame);
const gameHistoryRecordPlayVoting: GameHistoryRecordPlayVoting = {
result: this.generateCurrentGameHistoryRecordPlayVotingResultToInsert(baseGame, newGame, gameHistoryRecordToInsert),
nominatedPlayers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ export class GamePlayMakerService {

private async allVote({ votes, doesJudgeRequestAnotherVote }: MakeGamePlayWithRelationsDto, game: GameWithCurrentPlay): Promise<Game> {
let clonedGame = createGame(game) as GameWithCurrentPlay;
if (!votes) {
return clonedGame;
}
const nominatedPlayers = this.gamePlayVoteService.getNominatedPlayers(votes, clonedGame);
if (doesJudgeRequestAnotherVote === true) {
const gamePlayAllVote = createGamePlayAllVote({ cause: GamePlayCauses.STUTTERING_JUDGE_REQUEST });
Expand Down Expand Up @@ -160,9 +157,6 @@ export class GamePlayMakerService {
private allElectSheriff(play: MakeGamePlayWithRelationsDto, game: GameWithCurrentPlay): Game {
const clonedGame = createGame(game) as GameWithCurrentPlay;
const { votes } = play;
if (!votes) {
return clonedGame;
}
const nominatedPlayers = this.gamePlayVoteService.getNominatedPlayers(votes, clonedGame);
if (!nominatedPlayers.length) {
return clonedGame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import { RoleNames } from "@/modules/role/enums/role.enum";

@Injectable()
export class GamePlayVoteService {
public getNominatedPlayers(votes: MakeGamePlayVoteWithRelationsDto[], game: GameWithCurrentPlay): Player[] {
public getNominatedPlayers(votes: MakeGamePlayVoteWithRelationsDto[] | undefined, game: GameWithCurrentPlay): Player[] {
const clonedGame = createGame(game) as GameWithCurrentPlay;
let playerVoteCounts = this.getPlayerVoteCounts(votes, clonedGame);
playerVoteCounts = this.addRavenMarkVoteToPlayerVoteCounts(playerVoteCounts, clonedGame);
const maxVotes = Math.max(...playerVoteCounts.map(playerVoteCount => playerVoteCount[1]));
return playerVoteCounts.filter(playerVoteCount => playerVoteCount[1] === maxVotes).map(playerVoteCount => createPlayer(playerVoteCount[0]));
}

private getPlayerVoteCounts(votes: MakeGamePlayVoteWithRelationsDto[], game: GameWithCurrentPlay): PlayerVoteCount[] {
private getPlayerVoteCounts(votes: MakeGamePlayVoteWithRelationsDto[] | undefined, game: GameWithCurrentPlay): PlayerVoteCount[] {
if (!votes) {
return [];
}
const { hasDoubledVote: doesSheriffHaveDoubledVote } = game.options.roles.sheriff;
const sheriffPlayer = getPlayerWithActiveAttributeName(game, PlayerAttributeNames.SHERIFF);
return votes.reduce<PlayerVoteCount[]>((acc, vote) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"roles": {
"raven": {
"markPenalty": 3
}
}
}
71 changes: 71 additions & 0 deletions tests/acceptance/features/game/features/role/raven.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@raven-role

Feature: 馃惁鈥嶁瑳 Raven role

Scenario: 馃惁鈥嶁瑳 Raven marks a player but can also skip
Given a created game with options described in file no-sheriff-option.json and with the following players
| name | role |
| Antoine | raven |
| Olivia | werewolf |
| JB | villager |
| Camille | villager |
| Thomas | villager |
Then the game's current play should be raven to mark

When the player or group skips his turn
Then nobody should have the active raven-marked from raven attribute
And the game's current play should be werewolves to eat

When the werewolves eat the player named Thomas
Then the player named Thomas should be murdered by werewolves from eaten
And the game's current play should be all to vote

When the player or group skips his turn
Then the game's current play should be raven to mark

When the raven marks the player named JB
Then the player named JB should have the active raven-marked from raven attribute
And the game's current play should be werewolves to eat

When the werewolves eat the player named JB
Then the player named JB should be murdered by werewolves from eaten
And the player named JB should not have the active raven-marked from raven attribute

When the player or group skips his turn
Then the game's current play should be raven to mark

When the raven marks the player named Antoine
Then the player named Antoine should have the active raven-marked from raven attribute
And the game's current play should be werewolves to eat

When the werewolves eat the player named Camille
Then the player named Camille should be murdered by werewolves from eaten
And the game's current play should be all to vote

When the player or group skips his turn
Then the player named Antoine should be murdered by all from vote

Scenario: 馃惁鈥嶁瑳 Raven marks a player with a greater mark than the default one with good option
Given a created game with options described in file no-sheriff-option.json, raven-mark-penalty-is-three-option.json and with the following players
| name | role |
| Antoine | raven |
| Olivia | werewolf |
| JB | villager |
| Camille | villager |
| Thomas | villager |
Then the game's current play should be raven to mark

When the raven marks the player named JB
Then the player named JB should have the active raven-marked from raven attribute
And the game's current play should be werewolves to eat

When the werewolves eat the player named Thomas
Then the player named Thomas should be murdered by werewolves from eaten
And the game's current play should be all to vote

When all vote with the following votes
| voter | target |
| Olivia | Camille |
| JB | Camille |
| Antoine | Olivia |
Then the player named JB should be murdered by all from vote
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ When(/^the thief chooses card with role (?<cardRole>.+)$/u, async function(this:
this.game = this.response.json<Game>();
});

When(/^the raven marks the player named (?<name>.+)$/u, async function(this: CustomWorld, targetName: string): Promise<void> {
const target = getPlayerWithNameOrThrow(targetName, this.game, new Error("Player name not found"));
const makeGamePlayDto: MakeGamePlayDto = { targets: [{ playerId: target._id }] };

this.response = await makeGamePlayRequest(makeGamePlayDto, this.game, this.app);
this.game = this.response.json<Game>();
});

When(/^the player or group skips his turn$/u, async function(this: CustomWorld): Promise<void> {
this.response = await makeGamePlayRequest({}, this.game, this.app);
this.game = this.response.json<Game>();
Expand Down

0 comments on commit 0e29af5

Please sign in to comment.