seahaven-ap/packages/shared/src/pay-date.test.ts
Adam Moussa 46b570352a
feat(shared): add payment ladder and CSV domain package (AP-13) (#11)
* feat(shared): add payment ladder and CSV domain package

Introduce @seahaven-ap/shared via npm workspaces so FE and future API share
payments-dashboard-compatible status ladders, pay-date helpers, and CSV headers.

* fix(web): build shared package before vite dev

Ensure fresh npm ci && npm run dev (and Playwright webServer) can resolve
@seahaven-ap/shared dist exports that are gitignored.
2026-08-10 19:28:02 -04:00

30 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { isPlausibleSendYear, parseMDY, toCanonicalMDY, toISODate } from "./pay-date.js";
describe("pay-date helpers", () => {
it("parses M/D/YY and MM/DD/YYYY", () => {
expect(parseMDY("7/4/26")).toEqual({ year: 2026, month: 7, day: 4 });
expect(parseMDY("07/04/2026")).toEqual({ year: 2026, month: 7, day: 4 });
});
it("rejects invalid calendar dates and garbage", () => {
expect(parseMDY("2/30/2026")).toBeNull();
expect(parseMDY("2026-07-04")).toBeNull();
expect(parseMDY("")).toBeNull();
expect(parseMDY(null)).toBeNull();
});
it("formats ISO and canonical MDY", () => {
expect(toISODate("7/4/26")).toBe("2026-07-04");
expect(toCanonicalMDY("7/4/26")).toBe("07/04/2026");
expect(toISODate("bad")).toBeNull();
});
it("enforces the plausibility window relative to nowYear", () => {
expect(isPlausibleSendYear("01/01/2019", 2026)).toBe(true);
expect(isPlausibleSendYear("01/01/2018", 2026)).toBe(false);
expect(isPlausibleSendYear("01/01/2028", 2026)).toBe(true);
expect(isPlausibleSendYear("01/01/2029", 2026)).toBe(false);
expect(isPlausibleSendYear("not-a-date", 2026)).toBe(false);
});
});