import { describe, expect, test } from "bun:test"; import { htmlResponse } from "../../src/lib/response.ts"; describe("htmlResponse cache policy", () => { test("declares a private policy when no edge cache is requested", () => { const res = htmlResponse("
hi
"); expect(res.headers.get("Cache-Control")).toBe("private, no-store"); expect(res.headers.get("Vary")).toBeNull(); }); test("declares a private policy for a bare status argument", () => { const res = htmlResponse("nope
", 403); expect(res.status).toBe(403); expect(res.headers.get("Cache-Control")).toBe("private, no-store"); }); test("edgeCacheSeconds 0 is private, not silent", () => { const res = htmlResponse("hi
", { edgeCacheSeconds: 0 }); expect(res.headers.get("Cache-Control")).toBe("private, no-store"); }); test("a positive edge cache is public and varies on cookie", () => { const res = htmlResponse("hi
", { edgeCacheSeconds: 60 }); const cc = res.headers.get("Cache-Control") ?? ""; expect(cc).toContain("public"); expect(cc).toContain("s-maxage=60"); expect(cc).not.toContain("no-store"); expect(res.headers.get("Vary")).toContain("Cookie"); }); });