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 };