test: add Worker integration tests for routes and preferences

Exercise full HTML responses for week/show routes, modes, timezones, cookies, and zero-JS policy.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-02 18:42:50 -05:00
parent 5c996f1dda
commit a9f29141bc

120
src/integration.test.ts Normal file
View File

@@ -0,0 +1,120 @@
import { describe, it, expect } from "vitest";
import { SELF } from "cloudflare:test";
const FIXED_WEEK = "2026-W45";
describe("VCR Calendar integration", () => {
it("GET / redirects to /week", async () => {
const res = await SELF.fetch("https://vcr.test/", { redirect: "manual" });
expect(res.status).toBe(302);
expect(res.headers.get("Location")).toBe("/week");
});
it("GET /week returns valid HTML with required shell elements", async () => {
const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}`);
expect(res.status).toBe(200);
expect(res.headers.get("Content-Type")).toContain("text/html");
const html = await res.text();
expect(html).toContain("<!DOCTYPE html>");
expect(html).toMatch(/data-theme="/);
expect(html).toContain("week-grid");
expect(html).toContain("agenda");
expect(html).toContain("controls-bar");
expect(html).toContain("Bowl After Bowl");
expect(html).toContain("📻 VCR Calendar");
});
it("GET /week?mode=all shows all active shows including non-VCR", async () => {
const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&mode=all`);
const html = await res.text();
expect(html).toContain("Bowl After Bowl");
expect(html).toContain("Chad and Reeds");
expect(html).toContain("Hyper SpaceOut");
expect(html).toContain("vcr-badge");
});
it("GET /week?mode=vcr shows only VCR shows (BAB yes, HSO no)", async () => {
const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&mode=vcr`);
const html = await res.text();
expect(html).toContain("Bowl After Bowl");
expect(html).not.toContain("Hyper SpaceOut");
expect(html).not.toContain("Chad and Reeds");
});
it("GET /week?tz=pacific shows Pacific in controls and converts times", async () => {
const easternRes = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=eastern&mode=vcr`);
const easternHtml = await easternRes.text();
const pacificRes = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=pacific&mode=vcr`);
const pacificHtml = await pacificRes.text();
expect(pacificHtml).toContain('aria-current="true"');
expect(pacificHtml).toContain("Pacific");
expect(pacificHtml).toContain("Times shown in Pacific");
expect(easternHtml).toContain("10:00 PM");
expect(pacificHtml).toMatch(/Bowl After Bowl[\s\S]{0,400}7:00 PM/);
});
it("GET /week?tz=pacific sets a tz cookie", async () => {
const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=pacific`);
const cookies = res.headers.getAll("Set-Cookie");
expect(cookies.some((c) => c.includes("tz=pacific"))).toBe(true);
});
it("GET /week?theme=dark sets data-theme to dark", async () => {
const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&theme=dark`);
const html = await res.text();
expect(html).toContain('data-theme="dark"');
const cookies = res.headers.getAll("Set-Cookie");
expect(cookies.some((c) => c.includes("theme=dark"))).toBe(true);
});
it("GET /week?reset=1 clears preference cookies", async () => {
const res = await SELF.fetch(`https://vcr.test/week?reset=1`);
const cookies = res.headers.getAll("Set-Cookie");
expect(cookies.some((c) => c.includes("Max-Age=0"))).toBe(true);
});
it("GET /show/bowl-after-bowl returns show detail with schedule and hosts", async () => {
const res = await SELF.fetch("https://vcr.test/show/bowl-after-bowl");
expect(res.status).toBe(200);
expect(res.headers.get("Content-Type")).toContain("text/html");
const html = await res.text();
expect(html).toContain("Bowl After Bowl");
expect(html).toContain("Spencer");
expect(html).toContain("DuhLaurien");
expect(html).toContain("bowlafterbowl.com");
expect(html).toContain("Back to calendar");
expect(html).toContain("show-detail");
});
it("GET /show/nonexistent returns 404 with styled page", async () => {
const res = await SELF.fetch("https://vcr.test/show/nonexistent");
expect(res.status).toBe(404);
expect(res.headers.get("Content-Type")).toContain("text/html");
const html = await res.text();
expect(html).toContain("404");
expect(html).toContain("not-found");
});
it("returns no script tags on week or show pages", async () => {
const weekRes = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}`);
expect(await weekRes.text()).not.toContain("<script");
const showRes = await SELF.fetch("https://vcr.test/show/bowl-after-bowl");
expect(await showRes.text()).not.toContain("<script");
const notFoundRes = await SELF.fetch("https://vcr.test/show/missing-slug");
expect(await notFoundRes.text()).not.toContain("<script");
});
it("Hyper SpaceOut shows bi-weekly label in all mode", async () => {
const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&mode=all`);
const html = await res.text();
expect(html).toContain("bi-weekly");
});
it("GET /week?tz=amsterdam shows Amsterdam timezone as active", async () => {
const res = await SELF.fetch(`https://vcr.test/week?week=${FIXED_WEEK}&tz=amsterdam`);
const html = await res.text();
expect(html).toContain('aria-current="true"');
expect(html).toContain("Amsterdam");
expect(html).toContain("Times shown in Amsterdam");
});
});