/* @vitest-environment node */ import { describe, it, expect } from "vitest"; import { homePath, loginPath, branchPath, yearPath, monthPath, dayPath, searchPath, } from "./routes.js"; describe("lib/frontend/routes", () => { it("builds static paths", () => { expect(homePath()).toBe("/"); expect(loginPath()).toBe("/login"); }); it("builds branch-based paths", () => { expect(branchPath("NL01")).toBe("/NL01"); expect(yearPath("NL01", "2025")).toBe("/NL01/2025"); expect(monthPath("NL01", "2025", "12")).toBe("/NL01/2025/12"); expect(dayPath("NL01", "2025", "12", "31")).toBe("/NL01/2025/12/31"); expect(searchPath("NL01")).toBe("/NL01/search"); }); it("encodes dynamic segments defensively", () => { expect(branchPath("NL 01")).toBe("/NL%2001"); expect(yearPath("NL01", "2025/evil")).toBe("/NL01/2025%2Fevil"); }); it("throws for invalid segments", () => { expect(() => branchPath("")).toThrow(/must not be empty/i); expect(() => yearPath("NL01", "")).toThrow(/year/i); expect(() => monthPath("NL01", "2025", " ")).toThrow(/month/i); expect(() => dayPath("NL01", "2025", "12", "")).toThrow(/day/i); }); });