payments-dashboard/tests/postingDate.test.js

28 lines
1.2 KiB
JavaScript
Raw Normal View History

import { test } from "node:test";
import assert from "node:assert/strict";
import { postingDate } from "../src/fetchBoaTransactions.js";
test("postingDate: ISO asOfDate passes; valueDate is the fallback", () => {
assert.equal(postingDate({ asOfDate: "2026-07-22" }), "2026-07-22");
assert.equal(postingDate({ valueDate: "2026-07-21" }), "2026-07-21");
});
test("postingDate: non-ISO capture formats normalize", () => {
assert.equal(postingDate({ asOfDate: "7/21/2026" }), "2026-07-21");
});
test("postingDate: implausible years reject to null (epoch artifacts, far future)", () => {
// Security review INJ-002: "12/31/69" would become 2069 via the 2-digit
// fallback and permanently noop later real events on that record.
assert.equal(postingDate({ asOfDate: "12/31/69" }), null);
assert.equal(postingDate({ asOfDate: "9999-12-31" }), null);
assert.equal(postingDate({ asOfDate: "1901-01-01" }), null);
assert.equal(postingDate({ asOfDate: "garbage" }), null);
assert.equal(postingDate({}), null);
});
test("postingDate: empty-string asOfDate falls through to valueDate", () => {
// Open SWE review: ?? alone would return "" and reject the row.
assert.equal(postingDate({ asOfDate: "", valueDate: "2026-07-21" }), "2026-07-21");
});