Skip to content

Commit

Permalink
test(acceptance): acceptance tests for vote game play (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Sep 30, 2023
1 parent 9f9052c commit 7568e14
Show file tree
Hide file tree
Showing 12 changed files with 27,743 additions and 26,864 deletions.
10 changes: 9 additions & 1 deletion src/modules/game/helpers/game-play/game-play.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { MakeGamePlayTargetWithRelationsDto } from "@/modules/game/dto/make-game
import { MakeGamePlayVoteWithRelationsDto } from "@/modules/game/dto/make-game-play/make-game-play-vote/make-game-play-vote-with-relations.dto";
import { MakeGamePlayWithRelationsDto } from "@/modules/game/dto/make-game-play/make-game-play-with-relations.dto";
import type { MakeGamePlayDto } from "@/modules/game/dto/make-game-play/make-game-play.dto";
import { getAdditionalCardWithId, getPlayerWithId } from "@/modules/game/helpers/game.helper";
import { PlayerAttributeNames, PlayerGroups } from "@/modules/game/enums/player.enum";
import { getAdditionalCardWithId, getGroupOfPlayers, getPlayerWithId } from "@/modules/game/helpers/game.helper";
import { doesPlayerHaveActiveAttributeWithName } from "@/modules/game/helpers/player/player-attribute/player-attribute.helper";
import type { GameAdditionalCard } from "@/modules/game/schemas/game-additional-card/game-additional-card.schema";
import type { GamePlay } from "@/modules/game/schemas/game-play/game-play.schema";
import type { Game } from "@/modules/game/schemas/game.schema";
Expand Down Expand Up @@ -85,11 +87,17 @@ function areGamePlaysEqual(playA: GamePlay, playB: GamePlay): boolean {
return playA.action === playB.action && playA.cause === playB.cause && playA.source.name === playB.source.name;
}

function canSurvivorsVote(game: Game): boolean {
const survivors = getGroupOfPlayers(game, PlayerGroups.SURVIVORS);
return survivors.some(player => !doesPlayerHaveActiveAttributeWithName(player, PlayerAttributeNames.CANT_VOTE, game));
}

export {
getVotesWithRelationsFromMakeGamePlayDto,
getTargetsWithRelationsFromMakeGamePlayDto,
getChosenCardFromMakeGamePlayDto,
createMakeGamePlayDtoWithRelations,
findPlayPriorityIndex,
areGamePlaysEqual,
canSurvivorsVote,
};
2 changes: 1 addition & 1 deletion src/modules/game/helpers/game.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getLeftToEatByWhiteWerewolfPlayers(game: Game): Player[] {

function getGroupOfPlayers(game: Game, group: PlayerGroups): Player[] {
if (group === PlayerGroups.SURVIVORS) {
return game.players;
return game.players.filter(({ isAlive }) => isAlive);
}
if (group === PlayerGroups.LOVERS) {
return getPlayersWithActiveAttributeName(game, PlayerAttributeNames.IN_LOVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GamePlayCauses, WitchPotions } from "@/modules/game/enums/game-play.enu
import { GamePhases } from "@/modules/game/enums/game.enum";
import { PlayerAttributeNames, PlayerGroups } from "@/modules/game/enums/player.enum";
import { createGamePlay, createGamePlaySurvivorsElectSheriff, createGamePlaySurvivorsVote } from "@/modules/game/helpers/game-play/game-play.factory";
import { areGamePlaysEqual, findPlayPriorityIndex } from "@/modules/game/helpers/game-play/game-play.helper";
import { areGamePlaysEqual, canSurvivorsVote, findPlayPriorityIndex } from "@/modules/game/helpers/game-play/game-play.helper";
import { createGame } from "@/modules/game/helpers/game.factory";
import { areAllWerewolvesAlive, getExpectedPlayersToPlay, getGroupOfPlayers, getLeftToEatByWerewolvesPlayers, getLeftToEatByWhiteWerewolfPlayers, getPlayerDtoWithRole, getPlayersWithActiveAttributeName, getPlayersWithCurrentRole, getPlayerWithActiveAttributeName, getPlayerWithCurrentRole, isGameSourceGroup, isGameSourceRole } from "@/modules/game/helpers/game.helper";
import { canPiedPiperCharm, isPlayerAliveAndPowerful, isPlayerPowerful } from "@/modules/game/helpers/player/player.helper";
Expand Down Expand Up @@ -46,9 +46,12 @@ export class GamePlayService {
}

public getUpcomingDayPlays(game: Game): GamePlay[] {
const upcomingDayPlays: GamePlay[] = [createGamePlaySurvivorsVote()];
const upcomingDayPlays: GamePlay[] = [];
if (this.isSheriffElectionTime(game.options.roles.sheriff, game.turn, game.phase)) {
upcomingDayPlays.unshift(createGamePlaySurvivorsElectSheriff());
upcomingDayPlays.push(createGamePlaySurvivorsElectSheriff());
}
if (canSurvivorsVote(game)) {
upcomingDayPlays.push(createGamePlaySurvivorsVote());
}
return upcomingDayPlays;
}
Expand Down
6 changes: 5 additions & 1 deletion src/modules/game/providers/services/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export class GameService {
clonedGame = this.playerAttributeService.decreaseRemainingPhasesAndRemoveObsoletePlayerAttributes(clonedGame);
clonedGame = await this.gamePhaseService.switchPhaseAndAppendGamePhaseUpcomingPlays(clonedGame);
clonedGame = this.gamePhaseService.applyStartingGamePhaseOutcomes(clonedGame);
return this.gamePlayService.proceedToNextGamePlay(clonedGame);
clonedGame = this.gamePlayService.proceedToNextGamePlay(clonedGame);
if (isGamePhaseOver(clonedGame)) {
clonedGame = await this.handleGamePhaseCompletion(clonedGame);
}
return clonedGame;
}

private async updateGame(gameId: Types.ObjectId, gameDataToUpdate: Partial<Game>): Promise<Game> {
Expand Down
296 changes: 296 additions & 0 deletions tests/acceptance/features/game/features/game-play/vote.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
@vote-game-play

Feature: 🗳️ Vote Game Play

Scenario: 🗳 Majority of votes against a player kills him
Given a created game with options described in files no-sheriff-option.json and with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | villager |
| Thomas | villager |
Then the game's current play should be werewolves to eat

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

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Thomas | JB |
| Antoine | JB |
Then the player named JB should be murdered by survivors from vote

Scenario: 🗳 Tie in votes are dealt with another vote when there is no sheriff in town
Given a created game with options described in files no-sheriff-option.json and with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | villager |
| Thomas | villager |
Then the game's current play should be werewolves to eat

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

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the game's current play should be survivors to vote because previous-votes-were-in-ties

When the survivors vote with the following votes
| voter | target |
| Antoine | Thomas |
Then the player named Thomas should be murdered by survivors from vote
And the player named JB should be alive

Scenario: 🗳 None of the players are murdered when there is a tie in votes but survivors can't decide who to kill without sheriff
Given a created game with options described in files no-sheriff-option.json and with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | villager |
| Thomas | villager |
Then the game's current play should be werewolves to eat

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

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the game's current play should be survivors to vote because previous-votes-were-in-ties

When the survivors vote with the following votes
| voter | target |
| Antoine | Thomas |
| Thomas | JB |
Then the player named Thomas should be alive
And the player named JB should be alive
And the game's current play should be werewolves to eat

Scenario: 🗳 Sheriff has a doubled vote
Given a created game with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | villager |
| Thomas | villager |
Then the game's current play should be survivors to elect-sheriff

When the survivors elect sheriff with the following votes
| voter | target |
| Antoine | Olivia |
| Olivia | Antoine |
| JB | Antoine |
| Thomas | Antoine |
Then the player named Antoine should have the active sheriff from survivors attribute
And the game's current play should be werewolves to eat

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

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Antoine | JB |
Then the player named JB should be murdered by survivors from vote

Scenario: 🗳 Sheriff disparition in game brings back the classic tie in votes system
Given a created game with the following players
| name | role |
| Antoine | idiot |
| Olivia | villager |
| JB | werewolf |
| Thomas | villager |
Then the game's current play should be survivors to elect-sheriff

When the survivors elect sheriff with the following votes
| voter | target |
| Antoine | Olivia |
| Olivia | Antoine |
| JB | Antoine |
| Thomas | Antoine |
Then the player named Antoine should have the active sheriff from survivors attribute
And the game's current play should be werewolves to eat

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

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the player named JB should be alive
And the player named Thomas should be alive
And the game's current play should be survivors to vote because previous-votes-were-in-ties

When the survivors vote with the following votes
| voter | target |
| Olivia | Thomas |
| Thomas | JB |
| JB | Thomas |
Then the player named Thomas should be murdered by survivors from vote

Scenario: 🗳 Raven mark adds two votes to the player who has it
Given a created game with options described in files no-sheriff-option.json and with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | raven |
| Thomas | villager |
And 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
Then the game's current play should be werewolves to eat

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

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the player named JB should be murdered by survivors from vote

Scenario: 🗳 Scapegoat is murdered in case of tie and makes the next votes skipped by banning everyone from voting
Given a created game with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | scapegoat |
| Thomas | villager |
| Juju | villager |
| Doudou | villager |
Then the game's current play should be survivors to elect-sheriff

When the survivors elect sheriff with the following votes
| voter | target |
| Antoine | Olivia |
| Olivia | Antoine |
| JB | Antoine |
| Thomas | Antoine |
Then the player named Antoine should have the active sheriff from survivors attribute
And the game's current play should be werewolves to eat

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

When the survivors vote with the following votes
| voter | target |
| Doudou | Juju |
| Juju | Doudou |
Then the player named JB should be murdered by survivors from vote-scapegoated
And the game's current play should be scapegoat to ban-voting

When the scapegoat bans from vote the following players
| name |
| Juju |
| Doudou |
| Antoine |
| Thomas |
Then the game's current play should be werewolves to eat
And nobody should have the active cant-vote from scapegoat attribute

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 werewolves to eat
And the game's turn should be 3
And the game's phase should be night

Scenario: 🗳 Stuttering Judge asks for another vote after another vote
Given a created game with options described in files no-sheriff-option.json and with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | stuttering-judge |
| Thomas | villager |
And the game's current play should be stuttering-judge to choose-sign

When the stuttering judge chooses his sign
Then the game's current play should be werewolves to eat

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

When the survivors vote with the following votes and the stuttering judge does his sign
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the player named JB should be alive
And the player named Thomas should be alive
And the game's current play should be survivors to vote because previous-votes-were-in-ties

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the player named JB should be alive
And the player named Thomas should be alive
And the game's current play should be survivors to vote because stuttering-judge-request

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
Then the player named Thomas should be murdered by survivors from vote
And the game's current play should be werewolves to eat

Scenario: 🗳 Multiple votes can happen during the day with stuttering judge requests and ties
Given a created game with options described in files no-sheriff-option.json, stuttering-judge-two-vote-requests-option.json and with the following players
| name | role |
| Antoine | werewolf |
| Olivia | villager |
| JB | stuttering-judge |
| Thomas | villager |
And the game's current play should be stuttering-judge to choose-sign

When the stuttering judge chooses his sign
Then the game's current play should be werewolves to eat

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

When the survivors vote with the following votes and the stuttering judge does his sign
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the player named JB should be alive
And the player named Thomas should be alive
And the game's current play should be survivors to vote because previous-votes-were-in-ties

When the survivors vote with the following votes and the stuttering judge does his sign
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the player named JB should be alive
And the player named Thomas should be alive
And the game's current play should be survivors to vote because stuttering-judge-request

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
| Thomas | JB |
Then the player named JB should be alive
And the player named Thomas should be alive
And the game's current play should be survivors to vote because previous-votes-were-in-ties

When the survivors vote with the following votes
| voter | target |
| JB | Thomas |
Then the player named Thomas should be murdered by survivors from vote
And the game's current play should be survivors to vote because stuttering-judge-request

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

0 comments on commit 7568e14

Please sign in to comment.