diff --git a/src/__tests__/integration/reconcile-queue.test.ts b/src/__tests__/integration/reconcile-queue.test.ts index 75e8c5c..08bd613 100644 --- a/src/__tests__/integration/reconcile-queue.test.ts +++ b/src/__tests__/integration/reconcile-queue.test.ts @@ -66,4 +66,21 @@ describe("getPendingReconciliations", () => { expect(offered).toContain(live); expect(offered).not.toContain(dupe); }); + + it("offers the exact native twin of a foreign row even when its provisional AUD is far off", async () => { + // Live shape, 2026-10-09: wallet INR 112 at a provisional A$2.01; CommBank + // charged A$1.68 -- 16% under, outside the +-5% band. + const manual = await insertTransaction(pool, ownerId, { description: "SWIGGY LIMITED", amount: 2.01, transaction_date: "2026-10-04" }); + await pool.query(`UPDATE transactions SET foreign_currency_code = 'INR', foreign_currency_amount = 112 WHERE id = $1`, [manual]); + const twin = await statementLine(1.68, "2026-10-04", "Swiggy Limited Bengaluru"); + const otherRupees = await statementLine(1.68, "2026-10-04", "Swiggy Limited Bengaluru"); + await pool.query(`UPDATE transactions SET foreign_currency_code = 'INR', foreign_currency_amount = 112 WHERE id = $1`, [twin]); + await pool.query(`UPDATE transactions SET foreign_currency_code = 'INR', foreign_currency_amount = 113 WHERE id = $1`, [otherRupees]); + + const [row] = (await getPendingReconciliations(ownerId)).filter((r) => r.id === manual); + const offered = row.matches.map((m) => m.id); + expect(offered).toContain(twin); + // A different native figure at the same AUD is not admitted by this path. + expect(offered).not.toContain(otherRupees); + }); }); diff --git a/src/lib/queries.ts b/src/lib/queries.ts index 850bb16..a8480d3 100644 --- a/src/lib/queries.ts +++ b/src/lib/queries.ts @@ -903,7 +903,17 @@ export async function getPendingReconciliations(ownerId: number): Promise