Bank feeds: a row sent again under a new id updates the saved one
ING through Enable Banking gave every row a new transaction_id after linking again, so the 14-day re-fetch saved all of it a second time. - before inserting, a new-looking row is paired with a saved row of the same provider, account, day, amount and name whose id this fetch didn't return - the saved row takes the new id and keeps its category, name and tags - one saved row per new row, so two identical buys on a day stay two rows; visible rows are used before hidden ones Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
059a1da375
commit
5ef800e618
3 files changed
+70
-2
No files matched your search
@@ -1,7 +1,7 @@
|
||||
// Run: node src/lib/providers/feeds.test.ts
|
||||
import assert from "node:assert/strict";
|
||||
import { createVerify, generateKeyPairSync } from "node:crypto";
|
||||
import { basiqAccount, basiqStart, basiqTxn, belvoAccount, belvoStart, belvoTxn, ebAccount, ebJwt, ebStart, ebTxn, feedData, pemFrom, validCpf } from "./feeds.ts";
|
||||
import { basiqAccount, basiqStart, basiqTxn, belvoAccount, belvoStart, belvoTxn, ebAccount, ebJwt, ebStart, ebTxn, feedData, matchRenamed, pemFrom, validCpf } from "./feeds.ts";
|
||||
|
||||
const { privateKey, publicKey } = generateKeyPairSync("rsa", { modulusLength: 2048 });
|
||||
const pem = privateKey.export({ type: "pkcs8", format: "pem" }).toString();
|
||||
@@ -99,6 +99,26 @@ console.log("feeds: ok");
|
||||
const b = ebTxn({ transaction_id: "x2", entry_reference: "ref-9", booking_date: "2026-11-02", transaction_amount: { amount: "3.50" }, credit_debit_indicator: "DBIT", status: "BOOK" }, "u1")!;
|
||||
assert.equal(a.plaid_transaction_id, b.plaid_transaction_id);
|
||||
}
|
||||
// Linking again gave every row a new transaction_id: each new row takes over its saved twin instead of doubling.
|
||||
{
|
||||
const t = (id: string, date: string, amount: number, name: string) => ({ ...ebTxn({ transaction_id: id, booking_date: date, transaction_amount: { amount: String(amount) }, credit_debit_indicator: "DBIT", status: "BOOK", note: name }, "h")!, account_id: "acc" });
|
||||
const saved = [
|
||||
{ id: "s1", account_id: "acc", date: "2026-11-17", amount: "3.49", name: "Action" },
|
||||
{ id: "s2", account_id: "acc", date: "2026-11-17", amount: "3.49", name: "Action" }, // two identical buys
|
||||
{ id: "s3", account_id: "acc", date: "2026-11-17", amount: 14, name: "Pizza" },
|
||||
{ id: "s4", account_id: "other", date: "2026-11-17", amount: 14, name: "Pizza" }, // other account: never matched
|
||||
];
|
||||
const fresh = [t("n1", "2026-11-17", 3.49, "Action"), t("n2", "2026-11-17", 3.49, "Action"), t("n3", "2026-11-17", 3.49, "Action"), t("n4", "2026-11-17", 14, "Pizza"), t("n5", "2026-11-18", 14, "Pizza")];
|
||||
const m = matchRenamed(fresh, saved);
|
||||
assert.equal(m.size, 3); // two Actions and the pizza; the third Action and the next day's pizza are really new
|
||||
assert.deepEqual(new Set([m.get(fresh[0].plaid_transaction_id), m.get(fresh[1].plaid_transaction_id)]), new Set(["s1", "s2"]));
|
||||
assert.equal(m.get(fresh[2].plaid_transaction_id), undefined);
|
||||
assert.equal(m.get(fresh[3].plaid_transaction_id), "s3");
|
||||
assert.equal(m.get(fresh[4].plaid_transaction_id), undefined);
|
||||
// A hidden copy is only used when the visible one is taken.
|
||||
const h = matchRenamed([fresh[3]], [{ id: "hidden", account_id: "acc", date: "2026-11-17", amount: 14, name: "Pizza", ignored: true }, { id: "shown", account_id: "acc", date: "2026-11-17", amount: 14, name: "Pizza", ignored: false }]);
|
||||
assert.equal(h.get(fresh[3].plaid_transaction_id), "shown");
|
||||
}
|
||||
// A key pasted on one line keeps its own label, PKCS#1 included, and still signs.
|
||||
{
|
||||
const { generateKeyPairSync, createPrivateKey: load } = await import("node:crypto");
|
||||
|
||||
Reference in new issue
Block a user