/* @vitest-environment node */ import { describe, it, expect } from "vitest"; import { getSearchDateRangeValidation } from "./searchDateValidation.js"; describe("lib/frontend/search/searchDateValidation", () => { it("returns null when both dates are missing", () => { expect(getSearchDateRangeValidation(null, null)).toBe(null); expect(getSearchDateRangeValidation(undefined, undefined)).toBe(null); }); it("returns VALIDATION_SEARCH_DATE for invalid from", () => { expect(getSearchDateRangeValidation("2026/01/01", null)).toEqual({ code: "VALIDATION_SEARCH_DATE", message: "Invalid from date", details: { from: "2026/01/01" }, }); }); it("returns VALIDATION_SEARCH_DATE for invalid to", () => { expect(getSearchDateRangeValidation(null, "2026-99-01")).toEqual({ code: "VALIDATION_SEARCH_DATE", message: "Invalid to date", details: { to: "2026-99-01" }, }); }); it("returns VALIDATION_SEARCH_RANGE when from > to", () => { expect(getSearchDateRangeValidation("2026-01-10", "2026-01-09")).toEqual({ code: "VALIDATION_SEARCH_RANGE", message: "Invalid date range", details: { from: "2026-01-10", to: "2026-01-09" }, }); }); it("accepts from === to as a valid single-day range", () => { expect(getSearchDateRangeValidation("2026-01-10", "2026-01-10")).toBe(null); }); it("accepts open ranges", () => { expect(getSearchDateRangeValidation("2026-01-10", null)).toBe(null); expect(getSearchDateRangeValidation(null, "2026-01-10")).toBe(null); }); it("accepts a valid range", () => { expect(getSearchDateRangeValidation("2026-01-01", "2026-01-31")).toBe(null); }); });