/** * Tests for EmailNotifier - Email notification integration * * Tests cover: * - Email templates with HTML and text formats * - Template rendering * - Enable/disable behavior based on config * - Recipient lookup from userEmails mapping * - Multiple email providers (SMTP, SendGrid, SES) * - Error handling */ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { EmailNotifier, EMAIL_TEMPLATES } from '../../../src/modules/bmm/lib/notifications/email-notifier.js'; describe('EmailNotifier', () => { // ============ EMAIL_TEMPLATES Tests ============ describe('EMAIL_TEMPLATES', () => { it('should define all required event types', () => { const expectedTypes = [ 'feedback_round_opened', 'signoff_requested', 'document_approved', 'document_blocked', 'reminder' ]; for (const type of expectedTypes) { expect(EMAIL_TEMPLATES[type]).toBeDefined(); expect(EMAIL_TEMPLATES[type].subject).toBeTruthy(); expect(EMAIL_TEMPLATES[type].html).toBeTruthy(); expect(EMAIL_TEMPLATES[type].text).toBeTruthy(); } }); it('should have placeholders in subject lines', () => { expect(EMAIL_TEMPLATES.feedback_round_opened.subject).toContain('{{document_type}}'); expect(EMAIL_TEMPLATES.feedback_round_opened.subject).toContain('{{document_key}}'); }); it('should have matching placeholders in HTML and text', () => { const template = EMAIL_TEMPLATES.document_approved; // Both should contain key placeholders expect(template.html).toContain('{{document_type}}'); expect(template.html).toContain('{{document_key}}'); expect(template.html).toContain('{{title}}'); expect(template.html).toContain('{{version}}'); expect(template.text).toContain('{{document_type}}'); expect(template.text).toContain('{{document_key}}'); expect(template.text).toContain('{{title}}'); expect(template.text).toContain('{{version}}'); }); it('should have valid HTML structure', () => { const template = EMAIL_TEMPLATES.signoff_requested; expect(template.html).toContain(''); expect(template.html).toContain(''); expect(template.html).toContain(''); expect(template.html).toContain(''); expect(template.html).toContain(''); }); it('should have styled content in HTML templates', () => { const template = EMAIL_TEMPLATES.feedback_round_opened; expect(template.html).toContain('