Skip to content

Commit

Permalink
test(acceptance): acceptances tests for two sisters (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Aug 31, 2023
1 parent 2aae75b commit caa3960
Show file tree
Hide file tree
Showing 7 changed files with 23,420 additions and 23,166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ export class GamePlayService {
return !!witchPlayer && isPlayerAliveAndPowerful(witchPlayer, game) && (!doSkipCallIfNoTarget || !hasWitchUsedLifePotion || !hasWitchUsedDeathPotion);
}

private shouldBeCalledOnCurrentTurnInterval(wakingUpInterval: number, game: CreateGameDto | Game): boolean {
return (game.turn - 1) % wakingUpInterval === 0;
}

private isWhiteWerewolfGamePlaySuitableForCurrentPhase(game: CreateGameDto | Game): boolean {
const { wakingUpInterval } = game.options.roles.whiteWerewolf;
const shouldWhiteWerewolfBeCalledOnCurrentTurn = (game.turn - 1) % wakingUpInterval === 0;
const shouldWhiteWerewolfBeCalledOnCurrentTurn = this.shouldBeCalledOnCurrentTurnInterval(wakingUpInterval, game);
if (game instanceof CreateGameDto) {
return shouldWhiteWerewolfBeCalledOnCurrentTurn && !!getPlayerDtoWithRole(game, RoleNames.WHITE_WEREWOLF);
}
Expand Down Expand Up @@ -208,12 +212,12 @@ export class GamePlayService {

private isTwoSistersGamePlaySuitableForCurrentPhase(game: CreateGameDto | Game): boolean {
const { wakingUpInterval } = game.options.roles.twoSisters;
const shouldTwoSistersBeCalled = wakingUpInterval > 0;
const shouldTwoSistersBeCalledOnCurrentTurn = this.shouldBeCalledOnCurrentTurnInterval(wakingUpInterval, game);
if (game instanceof CreateGameDto) {
return shouldTwoSistersBeCalled && !!getPlayerDtoWithRole(game, RoleNames.TWO_SISTERS);
return shouldTwoSistersBeCalledOnCurrentTurn && !!getPlayerDtoWithRole(game, RoleNames.TWO_SISTERS);
}
const twoSistersPlayers = getPlayersWithCurrentRole(game, RoleNames.TWO_SISTERS);
return shouldTwoSistersBeCalled && twoSistersPlayers.length > 0 && twoSistersPlayers.every(sister => sister.isAlive);
return shouldTwoSistersBeCalledOnCurrentTurn && twoSistersPlayers.length > 0 && twoSistersPlayers.every(sister => sister.isAlive);
}

private async isRoleGamePlaySuitableForCurrentPhase(game: CreateGameDto | Game, gamePlay: GamePlay): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"roles": {
"twoSisters": {
"wakingUpInterval": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"roles": {
"twoSisters": {
"wakingUpInterval": 1
}
}
}
72 changes: 72 additions & 0 deletions tests/acceptance/features/game/features/role/two-sisters.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@two-sisters-role
Feature: 👯‍ Two sisters role

Scenario: 👯‍ Two sisters are called every other night and not called anymore if one dies
Given a created game with options described in file no-sheriff-option.json and with the following players
| name | role |
| Antoine | two-sisters |
| Olivia | two-sisters |
| JB | werewolf |
| Thomas | villager |
| Maxime | villager |
| Julien | villager |
Then the game's current play should be two-sisters to meet-each-other

When the two sisters meet each other
Then the game's current play should be werewolves to eat

When the werewolves eat the player named Julien
Then the player named Julien 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 werewolves to eat

When the werewolves eat the player named Maxime
Then the player named Maxime 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 two-sisters to meet-each-other

When the two sisters meet each other
Then 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 all to vote

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

Scenario: 👯‍ Two sisters are called never called when options say they are not called
Given a created game with options described in file no-sheriff-option.json, two-sisters-never-waking-up-option.json and with the following players
| name | role |
| Antoine | two-sisters |
| Olivia | two-sisters |
| JB | werewolf |
| Thomas | villager |
| Maxime | villager |
| Julien | villager |
Then the game's current play should be werewolves to eat

Scenario: 👯‍ Two sisters wake up every night when options say they are called every night
Given a created game with options described in file no-sheriff-option.json, two-sisters-waking-up-every-night-option.json and with the following players
| name | role |
| Antoine | two-sisters |
| Olivia | two-sisters |
| JB | werewolf |
| Thomas | villager |
| Maxime | villager |
| Julien | villager |
Then the game's current play should be two-sisters to meet-each-other

When the two sisters meet each other
Then the game's current play should be werewolves to eat

When the werewolves eat the player named Julien
Then the player named Julien 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 two-sisters to meet-each-other
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ When(/^the lovers meet each other$/u, async function(this: CustomWorld): Promise
this.game = this.response.json<Game>();
});

When(/^the two sisters meet each other$/u, async function(this: CustomWorld): Promise<void> {
this.response = await makeGamePlayRequest({}, this.game, this.app);
this.game = this.response.json<Game>();
});

When(/^the guard protects 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 }] };
Expand Down

0 comments on commit caa3960

Please sign in to comment.