diff options
author | Julien Dessaux | 2023-01-03 23:51:00 +0100 |
---|---|---|
committer | Julien Dessaux | 2023-01-03 23:51:00 +0100 |
commit | c5d2d7ca77a502ea607d2db5ecdec972bc76bc69 (patch) | |
tree | 877c4bb29aef5ba8de491d78cfc9ee7e31232ad7 /tests | |
parent | Continue adding tests (diff) | |
download | jeux-de-mots-c5d2d7ca77a502ea607d2db5ecdec972bc76bc69.tar.gz jeux-de-mots-c5d2d7ca77a502ea607d2db5ecdec972bc76bc69.tar.bz2 jeux-de-mots-c5d2d7ca77a502ea607d2db5ecdec972bc76bc69.zip |
Fixed fixtures and testing
Diffstat (limited to '')
-rw-r--r-- | tests/root.spec.js | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/tests/root.spec.js b/tests/root.spec.js index ffceda5..308d35c 100644 --- a/tests/root.spec.js +++ b/tests/root.spec.js @@ -5,14 +5,14 @@ import app from "../main.js"; const request = supertest(app); -describe.concurrent("Root handlers tests", async function() { - describe.concurrent("When not logged in", async function() { - it("/", async function() { request.get("/").expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/login$/); }); - it("/login", async function() { request.get("/login").expect("Content-Type", /text\/html/).expect(200, /<form action="\/login" method="post">/); }); - it("/logout", async function() { request.get("/logout").expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/$/); }); +describe.concurrent("Root handlers tests", function() { + describe.concurrent("When not logged in", function() { + it("GET /", async function() { await request.get("/").expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/login$/); }); + it("GET /login", async function() { await request.get("/login").expect("Content-Type", /text\/html/).expect(200, /<form action="\/login" method="post">/); }); + it("GET /logout", async function() { await request.get("/logout").expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/$/); }); }); - describe.concurrent("With valid credentials", async function() { + describe.concurrent("With valid credentials", function() { beforeEach(async function(ctx) { const authResponse = await request.post("/login") .send("username=Alice&password=Alice42!") @@ -21,14 +21,16 @@ describe.concurrent("Root handlers tests", async function() { .expect(302, /Redirecting to \/games$/); ctx.cookie = authResponse.get("Set-Cookie"); }); - it("/", async function(ctx) { request.get("/").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/games$/); }); - it("/login", async function(ctx) { request.get("/login").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/games$/); }); - describe("logout", async function(ctx) { - it("/logout", async function() { request.get("/logout").set("cookie", ctx.cookie).expect("content-type", /text\/plain/).expect("set-cookie", /JDMSessionId=;/).expect(302, /Redirecting to \/$/); }); + it("GET /", async function(ctx) { await request.get("/").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/games$/); }); + it("GET /login", async function(ctx) { await request.get("/login").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/games$/); }); + describe("logout", function() { + beforeEach(async function(ctx) { + await request.get("/logout").set("cookie", ctx.cookie).expect("content-type", /text\/plain/).expect("set-cookie", /JDMSessionId=;/).expect(302, /Redirecting to \/$/); + }); describe.concurrent("all handlers with the now invalid cookie", async function() { - it("/", async function() { request.get("/").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/login$/); }); - it("/", async function() { request.get("/login").set("Cookie", ctx.cookie).expect("Content-Type", /text\/html/).expect(200, /<form action="\/login" method="post">/); }); - it("/", async function() { request.get("/logout").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/$/); }); + it("GET /", async function(ctx) { await request.get("/").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/login$/); }); + it("GET /login", async function(ctx) { await request.get("/login").set("Cookie", ctx.cookie).expect("Content-Type", /text\/html/).expect(200, /<form action="\/login" method="post">/); }); + it("GET /logout", async function(ctx) { await request.get("/logout").set("Cookie", ctx.cookie).expect("Content-Type", /text\/plain/).expect(302, /Redirecting to \/$/); }); }); }); }); |