-
Notifications
You must be signed in to change notification settings - Fork 3
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 #28 from antoinezanardi/staging
Staging
- Loading branch information
Showing
7 changed files
with
134 additions
and
5 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
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
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,111 @@ | ||
const { describe, it, before, after } = require("mocha"); | ||
const chai = require("chai"); | ||
const chaiHttp = require("chai-http"); | ||
const app = require("../../../app"); | ||
const Config = require("../../../config"); | ||
const { resetDatabase } = require("../../../src/helpers/functions/Test"); | ||
|
||
chai.use(chaiHttp); | ||
const { expect } = chai; | ||
|
||
const credentials = { email: "test@test.fr", password: "secret" }; | ||
const players = [ | ||
{ name: "Dug", role: "hunter" }, // O | ||
{ name: "Dig", role: "villager" }, // 1 | ||
{ name: "Deg", role: "werewolf" }, // 2 | ||
{ name: "Dog", role: "werewolf" }, // 3 | ||
]; | ||
let token, game; | ||
|
||
// eslint-disable-next-line max-lines-per-function | ||
describe("H - Game where hunter kills mayor when day rises", () => { | ||
before(done => resetDatabase(done)); | ||
after(done => resetDatabase(done)); | ||
it("👤 Creates new user (POST /users)", done => { | ||
chai.request(app) | ||
.post("/users") | ||
.auth(Config.app.basicAuth.username, Config.app.basicAuth.password) | ||
.send(credentials) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
done(); | ||
}); | ||
}); | ||
it("🔑 Logs in successfully (POST /users/login)", done => { | ||
chai.request(app) | ||
.post(`/users/login`) | ||
.auth(Config.app.basicAuth.username, Config.app.basicAuth.password) | ||
.send(credentials) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
token = res.body.token; | ||
done(); | ||
}); | ||
}); | ||
it("🎲 Creates game with JWT auth (POST /games)", done => { | ||
chai.request(app) | ||
.post("/games") | ||
.set({ "Authorization": `Bearer ${token}` }) | ||
.send({ players }) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
game = res.body; | ||
done(); | ||
}); | ||
}); | ||
it("👪 All elect a werewolf as the sheriff (POST /games/:id/play)", done => { | ||
const { players } = game; | ||
chai.request(app) | ||
.post(`/games/${game._id}/play`) | ||
.set({ "Authorization": `Bearer ${token}` }) | ||
.send({ source: "all", action: "elect-sheriff", votes: [ | ||
{ from: players[0]._id, for: players[2]._id }, | ||
{ from: players[1]._id, for: players[2]._id }, | ||
] }) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
game = res.body; | ||
expect(game.players[2].attributes).to.deep.include({ attribute: "sheriff", source: "all" }); | ||
expect(game.history[0].play.votes).to.exist; | ||
done(); | ||
}); | ||
}); | ||
it("🐺 Werewolves eat the hunter (POST /games/:id/play)", done => { | ||
const { players } = game; | ||
chai.request(app) | ||
.post(`/games/${game._id}/play`) | ||
.set({ "Authorization": `Bearer ${token}` }) | ||
.send({ source: "werewolves", action: "eat", targets: [ | ||
{ player: players[0]._id }, | ||
] }) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
game = res.body; | ||
done(); | ||
}); | ||
}); | ||
it("☀️ Sun is rising and hunter is dead", done => { | ||
expect(game.phase).to.equals("day"); | ||
expect(game.players[0].isAlive).to.equals(false); | ||
done(); | ||
}); | ||
it("🔫 Hunter shoots at the sheriff werewolf (POST /games/:id/play)", done => { | ||
const { players } = game; | ||
chai.request(app) | ||
.post(`/games/${game._id}/play`) | ||
.set({ "Authorization": `Bearer ${token}` }) | ||
.send({ source: "hunter", action: "shoot", targets: [ | ||
{ player: players[2]._id }, | ||
] }) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
game = res.body; | ||
expect(game.players[2].isAlive).to.equals(false); | ||
done(); | ||
}); | ||
}); | ||
it("🎲 Game is waiting for 'sheriff' to 'delegate'", done => { | ||
expect(game.waiting[0]).to.deep.equals({ for: "sheriff", to: "delegate" }); | ||
done(); | ||
}); | ||
}); |
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