From cbfbf359e717392edfdf566d615f5c29cced9d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 31 Jul 2026 01:09:52 +0200 Subject: [PATCH] test(nutrients): assert the audit fires on every ingest, not only on a landing The existing test encoded the behaviour this release deliberately changed: the breadcrumb used to fire only when a row landed, which made the one durable trace of an ingest conditional on its success. It failed for the right reason. Rewritten to assert the new intent with the reasoning kept, and it goes red again if the condition returns. --- .../api/nutrients/batch/__tests__/route.test.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app/api/nutrients/batch/__tests__/route.test.ts b/src/app/api/nutrients/batch/__tests__/route.test.ts index b985d25c7..09dba1152 100644 --- a/src/app/api/nutrients/batch/__tests__/route.test.ts +++ b/src/app/api/nutrients/batch/__tests__/route.test.ts @@ -387,7 +387,12 @@ describe("POST /api/nutrients/batch — write semantics", () => { }); }); - it("writes the audit-ledger breadcrumb only when at least one row landed", async () => { + it("writes the audit-ledger breadcrumb on every call, landed rows or not", async () => { + // This used to fire only when `inserted + updated > 0`, which made the one + // durable trace of an ingest conditional on its success. A batch where every + // entry was rejected then looked exactly like a batch that never arrived, + // and on an empty table the two were indistinguishable from the record — + // which is what made "does the client even post?" unanswerable. await POST( postReq({ entries: [ @@ -395,7 +400,10 @@ describe("POST /api/nutrients/batch — write semantics", () => { ], }), ); - expect(auditLog).not.toHaveBeenCalled(); + expect(auditLog).toHaveBeenCalledWith( + "nutrient.batch.ingest", + expect.objectContaining({ userId: "user-1" }), + ); await POST( postReq({ @@ -404,10 +412,7 @@ describe("POST /api/nutrients/batch — write semantics", () => { ], }), ); - expect(auditLog).toHaveBeenCalledWith( - "nutrient.batch.ingest", - expect.objectContaining({ userId: "user-1" }), - ); + expect(auditLog).toHaveBeenCalledTimes(2); }); it("a failed bulk insert marks only the insert group skipped, without touching the update group", async () => {