import { afterAll, beforeAll, expect, test } from "bun:test"; import type { Server } from "bun"; import { startServer } from "../src/server"; import { mockups } from "../src/mockups/registry"; let server: Server; let base: string; beforeAll(() => { server = startServer(0); base = `http://localhost:${server.port}`; }); afterAll(() => server.stop(true)); test("registry has 15 mockups", () => expect(mockups).toHaveLength(15)); test("index links every mockup", async () => { const res = await fetch(base + "/"); expect(res.status).toBe(200); const html = await res.text(); for (const m of mockups) expect(html).toContain(`/mockups/${m.slug}/`); }); test("index shows every registry name, pitch and tryThis", async () => { const html = (await (await fetch(base + "/")).text()).replaceAll("&", "&"); for (const m of mockups) for (const text of [m.name, m.pitch, m.tryThis]) expect(html).toContain(text); }); for (const m of mockups) { test(`mockup ${m.slug} serves with credits hook`, async () => { const res = await fetch(`${base}/mockups/${m.slug}/`); expect(res.status).toBe(200); expect(await res.text()).toContain("data-fan-credits"); }); test(`mockup ${m.slug} without slash is ok or redirects`, async () => { const res = await fetch(`${base}/mockups/${m.slug}`, { redirect: "manual" }); if (res.status >= 300 && res.status < 400) expect(res.headers.get("location")).toContain(`/mockups/${m.slug}/`); else expect(res.status).toBe(200); }); }