import { sendMail } from '../../src/mailer'; /** * What sendMail says it did. * * It returns early in two cases that are indistinguishable from success at the * call site — SMTP unconfigured, and the recipient not on MAIL_ALLOWLIST — and * #260 needs to tell them apart so the admin is not told a link was emailed * when it was not. * * Only the two skip paths are covered here. A real send needs an SMTP server, * which a unit test has no business starting; the integration test in Task 4 * covers the route's behaviour instead. * * The allowlist's own behaviour — exact matches, plus-suffixes, domains, * refusals — is covered directly and hermetically in * backend/tests/unit/mailAllowlist.test.ts, against isAllowedRecipient itself. * There is deliberately no third test here that sets SMTP_USER/SMTP_PASSWORD * and an allowed recipient: that combination falls through both guards and * reaches the real transporter, which opens a live TLS connection to * smtp.gmail.com:465. Do not add one back. */ describe('what sendMail reports', () => { const original = { ...process.env }; afterEach(() => { process.env = { ...original }; }); it('says so when SMTP is not configured', async () => { delete process.env.SMTP_USER; delete process.env.SMTP_PASSWORD; await expect(sendMail('someone@example.com', 'subject', '
body
')).resolves.toBe( 'skipped-unconfigured' ); }); // The case that matters most: QA restricts delivery, and a blocked address // previously returned exactly as though it had sent. it('says so when the recipient is not on the allowlist', async () => { process.env.SMTP_USER = 'user'; process.env.SMTP_PASSWORD = 'password'; process.env.MAIL_ALLOWLIST = 'allowed@example.com'; await expect(sendMail('someone-else@example.com', 'subject', 'body
')).resolves.toBe( 'skipped-blocked' ); }); });