routes.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* @vitest-environment node */
  2. import { describe, it, expect } from "vitest";
  3. import {
  4. homePath,
  5. loginPath,
  6. branchPath,
  7. yearPath,
  8. monthPath,
  9. dayPath,
  10. searchPath,
  11. } from "./routes.js";
  12. describe("lib/frontend/routes", () => {
  13. it("builds static paths", () => {
  14. expect(homePath()).toBe("/");
  15. expect(loginPath()).toBe("/login");
  16. });
  17. it("builds branch-based paths", () => {
  18. expect(branchPath("NL01")).toBe("/NL01");
  19. expect(yearPath("NL01", "2025")).toBe("/NL01/2025");
  20. expect(monthPath("NL01", "2025", "12")).toBe("/NL01/2025/12");
  21. expect(dayPath("NL01", "2025", "12", "31")).toBe("/NL01/2025/12/31");
  22. expect(searchPath("NL01")).toBe("/NL01/search");
  23. });
  24. it("encodes dynamic segments defensively", () => {
  25. expect(branchPath("NL 01")).toBe("/NL%2001");
  26. expect(yearPath("NL01", "2025/evil")).toBe("/NL01/2025%2Fevil");
  27. });
  28. it("throws for invalid segments", () => {
  29. expect(() => branchPath("")).toThrow(/must not be empty/i);
  30. expect(() => yearPath("NL01", "")).toThrow(/year/i);
  31. expect(() => monthPath("NL01", "2025", " ")).toThrow(/month/i);
  32. expect(() => dayPath("NL01", "2025", "12", "")).toThrow(/day/i);
  33. });
  34. });