Something went wrong. Try again.
🌿 Collaborative wiki on ATProto forked from juprodh.me/lichen.wiki
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { afterAll, describe, expect, test } from "bun:test";import { cleanupWikiAndDependents } from "../helpers/cleanup.ts";import { ALICE, createDiff, emitNote, emitRevision, emitWiki,} from "./helpers.ts";import { fetch, loginCookie } from "./http-helpers.ts";
const PUBLIC_SLUG = "cache-public";const PRIVATE_SLUG = "cache-private";
const publicWiki = emitWiki(ALICE.did, "Cache Public", "public", PUBLIC_SLUG);const privateWiki = emitWiki( ALICE.did, "Cache Private", "private", PRIVATE_SLUG,);
for (const wiki of [publicWiki, privateWiki]) { const note = emitNote(ALICE.did, "page", "Page", wiki.uri); emitRevision(ALICE.did, note.uri, createDiff("", "Body text."));}
afterAll(() => { cleanupWikiAndDependents(PUBLIC_SLUG); cleanupWikiAndDependents(PRIVATE_SLUG);});
describe("cache headers on rendered pages", () => { test("an anonymous read of a public note is edge-cacheable", async () => { const res = await fetch("GET", `/@${ALICE.handle}/${PUBLIC_SLUG}/page`); expect(res.status).toBe(200); expect(res.headers.get("Cache-Control")).toContain("s-maxage"); });
test("the same note read with a session is not", async () => { const cookie = await loginCookie(ALICE.handle); const res = await fetch("GET", `/@${ALICE.handle}/${PUBLIC_SLUG}/page`, { cookie, }); expect(res.status).toBe(200); expect(res.headers.get("Cache-Control")).toBe("private, no-store"); });
test("a private wiki's note is never publicly cacheable", async () => { const cookie = await loginCookie(ALICE.handle); const res = await fetch("GET", `/@${ALICE.handle}/${PRIVATE_SLUG}/page`, { cookie, }); expect(res.status).toBe(200); expect(res.headers.get("Cache-Control")).toBe("private, no-store"); });
test("an access-denied page is not publicly cacheable", async () => { const res = await fetch("GET", `/@${ALICE.handle}/${PRIVATE_SLUG}/page`); expect(res.status).toBe(403); expect(res.headers.get("Cache-Control")).toBe("private, no-store"); });});