From 614c8b9b8f298488fe875276e4be39b19f23af42 Mon Sep 17 00:00:00 2001 From: Luca <102960244+Luca-Timo@users.noreply.github.com> Date: Fri, 29 May 2026 13:25:36 +0200 Subject: [PATCH] test(backup-integrity): tolerate both knex .returning('id') return shapes CI's SQLite returned `[N]` (plain int) from `.insert().returning('id')` while local SQLite returned `[{ id: N }]` (object form). The brittle `const [{ id }] = ...` destructure crashed on the int shape. Switched to the unwrap pattern used by the existing crmDb test harness so the suite runs on both PG and every SQLite/knex combo the project supports. --- .../__tests__/services/backupIntegrityService.test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/__tests__/services/backupIntegrityService.test.js b/backend/__tests__/services/backupIntegrityService.test.js index 4ab52b2e..52e2c6bf 100644 --- a/backend/__tests__/services/backupIntegrityService.test.js +++ b/backend/__tests__/services/backupIntegrityService.test.js @@ -77,7 +77,10 @@ describe('backupIntegrityService.verifyDocumentArtefacts', () => { it('flags a contract whose signed_pdf_path file is missing', async () => { // Reference a file that we deliberately never create on disk. - const [{ id }] = await db('contracts').insert({ + // knex's `.returning('id')` returns `[{ id: N }]` on Postgres and + // newer SQLite, but `[N]` (plain int) on some SQLite versions — + // unwrap both shapes the same way the crmDb test harness does. + const inserted = await db('contracts').insert({ customer_account_id: customerId, contract_number: 'C-2026-MISSING', status: 'sent', @@ -85,7 +88,7 @@ describe('backupIntegrityService.verifyDocumentArtefacts', () => { signed_pdf_path: 'business-docs/contract/2026/C-2026-MISSING.pdf', created_at: new Date(), }).returning('id'); - const contractId = typeof id === 'object' ? id.id : id; + const contractId = typeof inserted[0] === 'object' ? inserted[0].id : inserted[0]; const report = await backupIntegrityService.verifyDocumentArtefacts({ scope: ['contract'] }); const hit = report.missing.find((m) => m.rowId === contractId); @@ -123,7 +126,7 @@ describe('backupIntegrityService.verifyDocumentArtefacts', () => { 'business-docs/contract/2026/C-2026-TAMPER.pdf', 'tampered bytes on disk', ); - const [{ id }] = await db('contracts').insert({ + const inserted = await db('contracts').insert({ customer_account_id: customerId, contract_number: 'C-2026-TAMPER', status: 'fully_signed', @@ -134,7 +137,7 @@ describe('backupIntegrityService.verifyDocumentArtefacts', () => { signed_pdf_sha256: sha256('the ORIGINAL bytes the customer signed'), created_at: new Date(), }).returning('id'); - const contractId = typeof id === 'object' ? id.id : id; + const contractId = typeof inserted[0] === 'object' ? inserted[0].id : inserted[0]; const report = await backupIntegrityService.verifyDocumentArtefacts({ scope: ['contract'] }); const hit = report.hashMismatches.find((m) => m.rowId === contractId);