From e6c2ac91484a04b91dec94efbfb0f43e9dc387a2 Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Fri, 21 Aug 2026 20:08:12 +0200 Subject: [PATCH] =?UTF-8?q?longevity:=20test=20atomicit=C3=A0=20corretto?= =?UTF-8?q?=20-=20verifica=20rollback=20anche=20dei=20campi=20liberi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/longevity/questionario.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/longevity/questionario.test.ts b/tests/longevity/questionario.test.ts index a7a590c..81024e8 100644 --- a/tests/longevity/questionario.test.ts +++ b/tests/longevity/questionario.test.ts @@ -67,16 +67,19 @@ describe('compilazione del questionario', () => { it('fallimento a metà non lascia traccia: sessione, misure e note sono atomiche', () => { const db = dbPronto(); - // Passa null nel campo libero per provocare un errore NOT NULL nella tabella profilo_note. - // Questo forza il fallimento DOPO aver aperto la sessione e registrato le misure. + // Passa due campi liberi: il primo valido (farmaci), il secondo con null (obiettivi). + // Il primo insert su profilo_note avviene (per farmaci: 'nessuno'), poi fallisce su + // obiettivi quando tenta di eseguire testo.trim() su un null, lanciando un TypeError. + // Il rollback della transazione deve annullare anche il primo insert già avvenuto. expect(() => salvaCompilazione(db, { client_code: 'ISL-0001', data: '2026-08-21', risposte: { q_riposato: 6 }, - liberi: { farmaci: null as any }, // Tipo violato: NOT NULL + liberi: { farmaci: 'nessuno', obiettivi: null as any }, // null causa TypeError su .trim() }) ).toThrow(); // Verifica che la transazione sia stata rollback: niente sessione, niente misure, niente note. + // Se il rollback non funzionasse, almeno il record di farmaci resterebbe in profilo_note. const sessioni = db.prepare(`SELECT COUNT(*) n FROM sessioni`).get() as { n: number }; const misure = db.prepare(`SELECT COUNT(*) n FROM misure`).get() as { n: number }; const note = db.prepare(`SELECT COUNT(*) n FROM profilo_note`).get() as { n: number };