summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJulien Dessaux2023-01-02 20:25:51 +0100
committerJulien Dessaux2023-01-02 20:26:30 +0100
commit0eaad219114239b693a68110a42b984a4f4f5b29 (patch)
treef7dec8d1e0ae644caeaadca89a69f88a3a241478 /tests
parentBegan adding tests (diff)
downloadjeux-de-mots-0eaad219114239b693a68110a42b984a4f4f5b29.tar.gz
jeux-de-mots-0eaad219114239b693a68110a42b984a4f4f5b29.tar.bz2
jeux-de-mots-0eaad219114239b693a68110a42b984a4f4f5b29.zip
Continue adding tests
Diffstat (limited to 'tests')
-rw-r--r--tests/root.spec.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/root.spec.js b/tests/root.spec.js
new file mode 100644
index 0000000..ffceda5
--- /dev/null
+++ b/tests/root.spec.js
@@ -0,0 +1,35 @@
+import { beforeEach, describe, it } from "vitest";
+import supertest from "supertest";
+
+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("With valid credentials", async function() {
+ beforeEach(async function(ctx) {
+ const authResponse = await request.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");
+ });
+ 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 \/$/); });
+ 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 \/$/); });
+ });
+ });
+ });
+});