Skip to content

Commit

Permalink
test(acceptance): big bad wolf tests (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinezanardi committed Aug 13, 2023
1 parent 1dffd75 commit a3b301d
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"roles": {
"bigBadWolf": {
"isPowerlessIfWerewolfDies": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"roles": {
"doSkipCallIfNoTarget": true
}
}
160 changes: 160 additions & 0 deletions tests/acceptance/features/game/features/role/big-bad-wolf.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
Feature: 馃惡馃懝 Big Bad Wolf role

Scenario: 馃惡馃懝Big Bad Wolf eats every night but powerless if one werewolf dies
Given a created game with options described in file no-sheriff-options.json and with the following players
| name | role |
| Antoine | witch |
| JB | werewolf |
| Olivia | big-bad-wolf |
| Thomas | seer |

When the seer looks at the player named Antoine
Then the player named Antoine should have the seen from seer attribute
And the game's current play should be werewolves to eat
And the game's current play should be played by the following players
| name |
| JB |
| Olivia |

When the werewolves eat the player named Antoine
Then the player named Antoine should have the eaten from werewolves attribute
And the game's current play should be big-bad-wolf to eat
And the game's current play should be played by the following players
| name |
| Olivia |

When the big bad wolf eats the player named Thomas
Then the player named Thomas should have the eaten from big-bad-wolf attribute
And the game's current play should be witch to use-potions

When the witch uses life potion on the player named Thomas
Then the player named Antoine should be murdered by werewolves from eaten
But the player named Thomas should be alive
And the game's current play should be all to vote

When all vote with the following votes
| source | target |
| Olivia | JB |
| Thomas | JB |
Then the player named JB should be murdered by all from vote
And the game's current play should be seer to look

When the seer looks at the player named Olivia
Then the player named Olivia should have the seen from seer attribute
And the game's current play should be werewolves to eat
And the game's current play should be played by the following players
| name |
| Olivia |

When the werewolves eat the player named Thomas
Then the player named Thomas should be murdered by werewolves from eaten
And the game's status should be over
And the game's winners should be werewolves with the following players
| name |
| JB |
| Olivia |

Scenario: 馃惡馃懝Big Bad Wolf eats every night and not powerless if one werewolf dies
Given a created game with options described in file no-sheriff-options.json, big-bad-wolf-not-powerless-if-werewolf-dies-option.json and with the following players
| name | role |
| Antoine | witch |
| JB | werewolf |
| Olivia | big-bad-wolf |
| Thomas | seer |

When the seer looks at the player named Antoine
Then the player named Antoine should have the seen from seer attribute
And the game's current play should be werewolves to eat
And the game's current play should be played by the following players
| name |
| JB |
| Olivia |

When the werewolves eat the player named Antoine
Then the player named Antoine should have the eaten from werewolves attribute
And the game's current play should be big-bad-wolf to eat
And the game's current play should be played by the following players
| name |
| Olivia |

When the big bad wolf eats the player named Thomas
Then the player named Thomas should have the eaten from big-bad-wolf attribute
And the game's current play should be witch to use-potions

When the witch uses life potion on the player named Thomas
Then the player named Antoine should be murdered by werewolves from eaten
But the player named Thomas should be alive
And the game's current play should be all to vote

When all vote with the following votes
| source | target |
| Olivia | JB |
| Thomas | JB |
Then the player named JB should be murdered by all from vote
And the game's current play should be seer to look

When the seer looks at the player named Olivia
Then the player named Olivia should have the seen from seer attribute
And the game's current play should be werewolves to eat
And the game's current play should be played by the following players
| name |
| Olivia |

When the werewolves eat the player named Thomas
Then the player named Thomas should have the eaten from werewolves attribute
And the game's current play should be big-bad-wolf to eat

When the player or group skips his turn
Then the player named Thomas should be murdered by werewolves from eaten
And the game's status should be over
And the game's winners should be werewolves with the following players
| name |
| JB |
| Olivia |

Scenario: 馃惡馃懝Big Bad Wolf eats every night but his role is skipped if no targets
Given a created game with options described in file no-sheriff-options.json, skip-roles-call-if-no-target-option.json and with the following players
| name | role |
| Antoine | witch |
| JB | werewolf |
| Olivia | big-bad-wolf |
| Thomas | guard |
| Doudou | villager |

When the guard protects the player named Antoine
Then the player named Antoine should have the protected from guard 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 have the eaten from werewolves attribute
And the game's current play should be big-bad-wolf to eat
And the game's current play should be played by the following players
| name |
| Olivia |

When the big bad wolf eats the player named Doudou
Then the player named Doudou should have the eaten from big-bad-wolf attribute
And the game's current play should be witch to use-potions

When the player or group skips his turn
Then the player named Doudou should be murdered by big-bad-wolf from eaten
But the player named Antoine should be alive
And the game's current play should be all to vote

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

When the werewolves eat the player named Antoine
Then the game's current play should be witch to use-potions

When the player or group skips his turn
Then the player named Antoine should be murdered by werewolves from eaten
And the game's status should be over
And the game's winners should be werewolves with the following players
| name |
| JB |
| Olivia |
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DataTable } from "@cucumber/cucumber";
import { Given } from "@cucumber/cucumber";
import { plainToInstance } from "class-transformer";
import { construct, crush } from "radash";
import { CreateGameDto } from "../../../../../src/modules/game/dto/create-game/create-game.dto";
import type { GameOptions } from "../../../../../src/modules/game/schemas/game-options/game-options.schema";
import type { Game } from "../../../../../src/modules/game/schemas/game.schema";
Expand All @@ -18,9 +19,16 @@ Given(/^a created game described in file (?<filename>.+\.json)$/u, async functio
});

Given(
/^a created game(?: with options described in file (?<filename>.+\.json) and)? with the following players$/u,
async function(this: CustomWorld, fileName: string | null, playersDatatable: DataTable): Promise<void> {
const options = fileName !== null ? readJsonFile<GameOptions>("game", fileName) : {};
/^a created game(?: with options described in files? (?<filename>(?:[\w-]+\.json(?:,\s)?)+) and)? with the following players$/u,
async function(this: CustomWorld, fileNames: string | null, playersDatatable: DataTable): Promise<void> {
let options = {};
if (fileNames !== null) {
const flatOptions = fileNames.split(",").reduce((acc, fileName) => {
const flatOption = crush(readJsonFile<GameOptions>("game", fileName.trim()));
return { ...acc, ...flatOption };
}, {});
options = construct<Record<string, unknown>>(flatOptions);
}
const players = convertDatatableToCreateGamePlayersDto(playersDatatable.rows());
const createGameDto: CreateGameDto = plainToInstance(CreateGameDto, { players, options }, plainToInstanceDefaultOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ When(/^the werewolves eat the player named (?<name>.+)$/u, async function(this:
this.game = this.response.json<Game>();
});

When(/^the big bad wolf eats 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 witch uses (?<potion1>life|death) potion on the player named (?<name1>.+?)(?: and (?<potion2>(?!\k<potion1>)(?:life|death)) potion on the player named (?<name2>.+?))?$/u,
async function(this: CustomWorld, firstPotion: WITCH_POTIONS, firstTargetName: string, secondPotion: WITCH_POTIONS | null, secondTargetName: string | null): Promise<void> {
Expand Down

0 comments on commit a3b301d

Please sign in to comment.