import { describe, expect, it } from "vitest"; import { renderSite } from "../../site/pages.ts"; import worker from "../index.ts"; import type { Env } from "../env.ts"; /** The asset layer, as a marker of which page was asked for. */ const asked: string[] = []; const env = { PUBLIC_ORIGIN: "https://cottondb.com", ASSETS: { fetch: async (req: Request) => { asked.push(new URL(req.url).pathname); return new Response("invite page", { status: 200, headers: { "Content-Type": "text/html" } }); }, }, } as unknown as Env; describe("a Circle invitation link, /c/", () => { it("answers the one invitation page for any code, kept by no cache", async () => { asked.length = 0; const res = await worker.fetch(new Request("https://cottondb.com/c/k3x9q2"), env); expect(res.status).toBe(200); expect(await res.text()).toBe("invite page"); expect(asked).toEqual(["/invite"]); expect(res.headers.get("Cache-Control")).toBe("no-store"); }); it("is a plain page that names nobody, says how to get Cotton and to open the link on the phone", () => { const html = renderSite()["invite.html"]!; expect(html).toContain("You are invited"); expect(html).toContain('href="/comms#get"'); expect(html).toMatch(/Open this link again on your phone/); expect(html).not.toMatch(/\+\d{6,}/); }); });