import { describe, expect, it } from 'vitest'; import { renderFailureMail } from './mail.js'; const input = { backupId: '20260711-030000', error: 'pg_dump failed: connection refused', lastSuccessAt: '2026-07-10T03:00:12.000Z', }; describe('renderFailureMail', () => { it('renders the English alert with all details interpolated', () => { const mail = renderFailureMail(input, 'en', 'dorfteich-test'); expect(mail.subject).toBe('[dorfteich-test] Backup failed (20260711-030000)'); expect(mail.text).toContain('Backup id: 20260711-030000'); expect(mail.text).toContain('Error: pg_dump failed: connection refused'); expect(mail.text).toContain('Last successful backup: 2026-07-10T03:00:12.000Z'); }); it('renders the German alert', () => { const mail = renderFailureMail(input, 'de', 'dorfteich-test'); expect(mail.subject).toBe('[dorfteich-test] Backup fehlgeschlagen (20260711-030000)'); expect(mail.text).toContain('Fehler: pg_dump failed: connection refused'); }); it('states when no backup ever succeeded', () => { const mail = renderFailureMail({ ...input, lastSuccessAt: null }, 'en', 'Dorfteich'); expect(mail.text).toContain('Last successful backup: none yet'); }); });