🌿 Collaborative wiki on ATProto lichen.wiki
atproto
14
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add more route tests

juprodh 35fa9d4b 1fb507f5

+112 -1
+44
tests/server/routes/explore.test.ts
··· 1 + import { describe, expect, test } from "bun:test"; 2 + import { createTestApp } from "./helpers.ts"; 3 + 4 + const app = createTestApp(); 5 + 6 + describe("explore route", () => { 7 + test("GET /explore returns 200 with HTML", async () => { 8 + const res = await app.handle(new Request("http://localhost/explore")); 9 + expect(res.status).toBe(200); 10 + expect(res.headers.get("Content-Type")).toContain("text/html"); 11 + }); 12 + 13 + test("GET /explore accepts sort parameter", async () => { 14 + const res = await app.handle( 15 + new Request("http://localhost/explore?sort=created"), 16 + ); 17 + expect(res.status).toBe(200); 18 + }); 19 + 20 + test("GET /explore accepts page parameter", async () => { 21 + const res = await app.handle( 22 + new Request("http://localhost/explore?page=1"), 23 + ); 24 + expect(res.status).toBe(200); 25 + }); 26 + 27 + test("GET /wikis redirects to /explore", async () => { 28 + const res = await app.handle( 29 + new Request("http://localhost/wikis", { redirect: "manual" }), 30 + ); 31 + expect(res.status).toBe(301); 32 + expect(res.headers.get("Location")).toBe("/explore"); 33 + }); 34 + 35 + test("GET /wikis preserves query params in redirect", async () => { 36 + const res = await app.handle( 37 + new Request("http://localhost/wikis?sort=created", { 38 + redirect: "manual", 39 + }), 40 + ); 41 + expect(res.status).toBe(301); 42 + expect(res.headers.get("Location")).toBe("/explore?sort=created"); 43 + }); 44 + });
+5 -1
tests/server/routes/helpers.ts
··· 45 45 const { noteRoutes } = await import("../../../src/server/routes/note.ts"); 46 46 const { searchRoutes } = await import("../../../src/server/routes/search.ts"); 47 47 const { wikiRoutes } = await import("../../../src/server/routes/wiki.ts"); 48 + const { exploreRoutes } = await import("../../../src/server/routes/explore.ts"); 49 + const { localeRoutes } = await import("../../../src/server/routes/locale.ts"); 48 50 49 51 export function createTestApp() { 50 52 return new Elysia() ··· 60 62 .use(searchRoutes) 61 63 .use(membershipRoutes) 62 64 .use(noteRoutes) 63 - .use(wikiRoutes); 65 + .use(wikiRoutes) 66 + .use(exploreRoutes) 67 + .use(localeRoutes); 64 68 } 65 69 66 70 /** Create a Request with an authenticated session cookie. */
+63
tests/server/routes/locale.test.ts
··· 1 + import { describe, expect, test } from "bun:test"; 2 + import { createTestApp } from "./helpers.ts"; 3 + 4 + const app = createTestApp(); 5 + 6 + describe("locale route", () => { 7 + test("POST /set-locale sets cookie and redirects", async () => { 8 + const body = new URLSearchParams({ locale: "fr" }); 9 + const res = await app.handle( 10 + new Request("http://localhost/set-locale", { 11 + method: "POST", 12 + headers: { "Content-Type": "application/x-www-form-urlencoded" }, 13 + body: body.toString(), 14 + }), 15 + ); 16 + 17 + expect(res.status).toBe(302); 18 + const cookie = res.headers.get("Set-Cookie") ?? ""; 19 + expect(cookie).toContain("locale=fr"); 20 + }); 21 + 22 + test("POST /set-locale redirects to referer", async () => { 23 + const body = new URLSearchParams({ locale: "en" }); 24 + const res = await app.handle( 25 + new Request("http://localhost/set-locale", { 26 + method: "POST", 27 + headers: { 28 + "Content-Type": "application/x-www-form-urlencoded", 29 + Referer: "/wiki/my-wiki", 30 + }, 31 + body: body.toString(), 32 + }), 33 + ); 34 + 35 + expect(res.status).toBe(302); 36 + expect(res.headers.get("Location")).toBe("/wiki/my-wiki"); 37 + }); 38 + 39 + test("POST /set-locale rejects invalid locale", async () => { 40 + const body = new URLSearchParams({ locale: "xx" }); 41 + const res = await app.handle( 42 + new Request("http://localhost/set-locale", { 43 + method: "POST", 44 + headers: { "Content-Type": "application/x-www-form-urlencoded" }, 45 + body: body.toString(), 46 + }), 47 + ); 48 + 49 + expect(res.status).toBe(400); 50 + }); 51 + 52 + test("POST /set-locale rejects missing locale", async () => { 53 + const res = await app.handle( 54 + new Request("http://localhost/set-locale", { 55 + method: "POST", 56 + headers: { "Content-Type": "application/x-www-form-urlencoded" }, 57 + body: "", 58 + }), 59 + ); 60 + 61 + expect(res.status).toBe(400); 62 + }); 63 + });