payments-dashboard/tests/postingDate.test.js
Adam Moussa d8a2412d75
Some checks are pending
Deploy / deploy (push) Waiting to run
fix(fetchboa): read real CashPro field names; extend BAI code map; 7-day window (#75)
The deployed v2 pipeline was fully inert: the classifier never read
detailText (where the live API carries the ACH DES:PAYMENTS text) and
the handler keyed event dates off valueDate, which the API does not
send (it sends asOfDate) — so ACH could not classify and no event of
any kind could apply. Both proven against real captured responses.

- classifyTransaction: detailText first in the description chain;
  Summary-row guard (new "summary" event); all-zeros customerReference
  normalizes to empty instead of fabricating check number 0.
- BAI_CODE_EVENTS: empirical enumeration lands — 255 + 252 are both
  check-numbered return credits, 266 is the no-number return credit
  (text disambiguates ach_return vs electronic_return via new
  fallbackEvent semantics), 455 is ach_debit via DES text or ignored
  third-party autopay, 170/201/470/481 are noise.
- postingDate helper (asOfDate ?? valueDate) drives both the sort and
  event dates; unmatched reason is now "missing posting date".
- Default replay window widened to trailing 7 days ending yesterday:
  self-healing across missed runs; responses verified pagination-free.

Refs: #66, #69
2026-07-22 15:40:49 -04:00

27 lines
1.2 KiB
JavaScript

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");
});