Files
Epic-The-Musical-Timeline/tests/server.test.ts
T

51 lines
2.0 KiB
TypeScript

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<undefined>;
let base: string;
beforeAll(() => { server = startServer(0); base = `http://localhost:${server.port}`; });
afterAll(() => server.stop(true));
test("registry has 17 mockups", () => expect(mockups).toHaveLength(17));
test("gallery links every mockup", async () => {
const res = await fetch(base + "/mockups/");
expect(res.status).toBe(200);
const html = await res.text();
for (const m of mockups) expect(html).toContain(`/mockups/${m.slug}/`);
});
test("gallery shows every registry name, pitch and tryThis", async () => {
const html = (await (await fetch(base + "/mockups/")).text()).replaceAll("&amp;", "&");
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);
});
}
test("the app is served at / with the credits hook", async () => {
const res = await fetch(base + "/");
expect(res.status).toBe(200);
const html = await res.text();
expect(html).toContain('id="voyage-app"');
expect(html).toContain("data-fan-credits");
});
test("/mockups redirects to the gallery", async () => {
const res = await fetch(base + "/mockups", { redirect: "manual" });
expect(res.status).toBe(302);
expect(res.headers.get("location")).toContain("/mockups/");
});