describe('NotificationService.sendWeeklyCompletionEmail', () => {
it('should send email and log to DB on success', async () => {
const resendMock = jest.fn().mockResolvedValue({ id: 'res_abc123' });
const result = await sendWeeklyCompletionEmail({
patientName: 'Ana García',
dietistEmail: 'dra.gomez@nutriflow.app',
macros: { calorias: 2100, proteinas: 142, carbos: 230, grasas: 65 },
adherencia: 87, patientId: 'pat_01'
});
expect(resendMock).toHaveBeenCalledOnce();
expect(result.status).toBe('sent');
});
it('should NOT throw when Resend fails — silent catch', async () => {
const resendMock = jest.fn().mockRejectedValue(new Error('API 500'));
await expect(sendWeeklyCompletionEmail({...})).resolves.toBeDefined();
});
it('should throw ConfigError at boot if RESEND_API_KEY missing', () => {
delete process.env.RESEND_API_KEY;
expect(() => require('./notification.service')).toThrow('ConfigError');
});
});
✓ 17 tests passed
coverage: 81% (+7pp)
Jest 3.2s