From 23bc58660d33d90ba7e6e031e59c3f1de8b3bc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Wed, 21 Oct 2026 00:03:08 +0200 Subject: [PATCH] test(integration): keep two cases independent of file order and random ids The backup schedule case assumed the shared database had no queue schema, but files that drive the queue create it and one leaves a finished backup run behind, so the case failed whenever it ran after them. It now clears that queue's history first. The delegate refusal case scanned the raw response for a digit run that the random request id can contain; the id is taken out before the scan. --- tests/integration/admin-backups-audit.test.ts | 16 +++++++++++++--- tests/integration/mood-context-linkage.test.ts | 10 ++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/integration/admin-backups-audit.test.ts b/tests/integration/admin-backups-audit.test.ts index 1417525e0..0a68fd32a 100644 --- a/tests/integration/admin-backups-audit.test.ts +++ b/tests/integration/admin-backups-audit.test.ts @@ -225,6 +225,16 @@ describe("GET /api/admin/backups — schedule health", () => { data: { userId: admin.id, type: "MANUAL_UPLOAD_1", data: blob }, }); + // Files that drive the queue create the `pgboss` schema in the shared + // database, and one of them leaves a finished backup run behind. Clear + // that queue's history so this case reads the same in every file order. + const [queueTable] = await prisma.$queryRaw>` + SELECT to_regclass('pgboss.job')::text AS t + `; + if (queueTable?.t) { + await prisma.$executeRaw`DELETE FROM pgboss.job WHERE name = 'data-backup'`; + } + // The listing handler declares no parameters; `apiHandler` reads the // request defensively out of its arguments, so calling it bare is what a // zero-argument handler supports. @@ -255,9 +265,9 @@ describe("GET /api/admin/backups — schedule health", () => { expect(body.data.schedule.lastSuccessAgeDays).toBe(46); expect(body.data.schedule.stale).toBe(true); - // No `pgboss` schema in the test database — the run reader fails soft to - // null rather than taking the whole page down, which is the arm a web-only - // deployment lives on permanently. + // No remembered run, or no `pgboss` schema at all — the run reader fails + // soft to null rather than taking the whole page down, which is the arm a + // web-only deployment lives on permanently. expect(body.data.schedule.lastRun).toBeNull(); expect(body.data.schedule.lastRunFailed).toBe(false); }); diff --git a/tests/integration/mood-context-linkage.test.ts b/tests/integration/mood-context-linkage.test.ts index 13db69e77..e3230ec3f 100644 --- a/tests/integration/mood-context-linkage.test.ts +++ b/tests/integration/mood-context-linkage.test.ts @@ -524,10 +524,12 @@ describe("mood context linkage (real Postgres)", () => { expect(res.status).toBe(403); const raw = await res.text(); // Asserted on the bytes, not on a parsed field: the point is that not one - // of the owner's figures reached the response. - expect(raw).not.toContain("7777"); - expect(raw).not.toContain("55"); - expect(raw).not.toContain("functionalImpact"); + // of the owner's figures reached the response. The request id is random + // and can contain any digit run, so it is taken out before the check. + const bytes = raw.replace(/"requestId":"[^"]*"/, ""); + expect(bytes).not.toContain("7777"); + expect(bytes).not.toContain("55"); + expect(bytes).not.toContain("functionalImpact"); }); it("refuses a malformed day", async () => {