mirror of
https://github.com/Sea-Haven-Industries/seahaven-ap.git
synced 2026-10-07 16:18:53 +00:00
31 lines
1.2 KiB
TypeScript
31 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);
|
||
|
|
});
|
||
|
|
});
|