diff options
author | Julien Dessaux | 2023-01-04 18:19:08 +0100 |
---|---|---|
committer | Julien Dessaux | 2023-01-04 18:19:08 +0100 |
commit | ea86dc22ce704c85f5f8e4b600e3395ef7ba3612 (patch) | |
tree | 9b049a788ea4d804e08de17ea4ba380e97f6bda9 | |
parent | Fixed fixtures and testing (diff) | |
download | jeux-de-mots-ea86dc22ce704c85f5f8e4b600e3395ef7ba3612.tar.gz jeux-de-mots-ea86dc22ce704c85f5f8e4b600e3395ef7ba3612.tar.bz2 jeux-de-mots-ea86dc22ce704c85f5f8e4b600e3395ef7ba3612.zip |
Added more tests
-rw-r--r-- | tests/games.spec.js | 23 | ||||
-rw-r--r-- | views/game.ejs | 2 |
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/games.spec.js b/tests/games.spec.js new file mode 100644 index 0000000..00ae1e7 --- /dev/null +++ b/tests/games.spec.js @@ -0,0 +1,23 @@ +import { beforeEach, describe, test } from "vitest"; +import supertest from "supertest"; + +import app from "../main.js"; + +describe.concurrent("Games handlers tests", function() { + describe.concurrent("When not logged in", function() { + test("GET /games", async function() { await supertest(app).get("/games").expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/login$/); }); + test("GET /games/1", async function() { await supertest(app).get("/games").expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/login$/); }); + }); + describe.concurrent("With valid credentials", function() { + beforeEach(async function(ctx) { + const authResponse = await supertest(app).post("/login") + .send("username=Alice&password=Alice42!") + .expect("Content-Type", /text\/plain/) + .expect("set-cookie", /JDMSessionId=/) + .expect(302, /Redirecting to \/games$/); + ctx.cookie = authResponse.get("Set-Cookie"); + }); + test("GET /games", async function(ctx) { await supertest(app).get("/games").set("Cookie", ctx.cookie).expect("Content-Type", /text\/html/).expect(200, /<td><a href="\/games\/1">Alice vs Bob<\/a><\/td>/); }); + test("GET /games/1", async function(ctx) { await supertest(app).get("/games/1").set("Cookie", ctx.cookie).expect("Content-Type", /text\/html/).expect(200, /<h2>Alice vs Bob<\/h2>/); }); + }); +}); diff --git a/views/game.ejs b/views/game.ejs index 7fae405..acbb95f 100644 --- a/views/game.ejs +++ b/views/game.ejs @@ -1,5 +1,5 @@ <%- include("header") %> -<h2>À vous de jouer</h2> +<h2><%- data.name %></h2> <table id="board"> <tr><td id="s0_0" class="tw" title="triple word"><td id="s0_1"><td id="s0_2"><td id="s0_3" class="dl" title="double letter"><td id="s0_4"><td id="s0_5"><td id="s0_6"><td id="s0_7" class="tw" title="triple word"><td id="s0_8"><td id="s0_9"><td id="s0_10"><td id="s0_11" class="dl" title="double letter"><td id="s0_12"><td id="s0_13"><td id="s0_14" class="tw" title="triple word"></tr> <tr><td id="s1_0"><td id="s1_1" class="dw" title="double word"><td id="s1_2"><td id="s1_3"><td id="s1_4"><td id="s1_5" class="tl" title="triple letter"><td id="s1_6"><td id="s1_7"><td id="s1_8"><td id="s1_9" class="tl" title="triple letter"><td id="s1_10"><td id="s1_11"><td id="s1_12"><td id="s1_13" class="dw" title="double word"><td id="s1_14"></tr> |