import assert from 'node:assert/strict'; import test from 'node:test'; import { buildWorkspaceInviteEmail } from './workspaceInviteEmail.js'; const input = { name: '', email: 'pat@example.test', inviterName: 'Alex & Sam', flockName: '', role: 'caregiver' as const, frontendUrl: 'https://flockpal.test/' }; test('invitation uses branded layout, escaped copy, and email-specific sign-in instructions', async () => { const mail = await buildWorkspaceInviteEmail(input); assert.match(String(mail.html), /<Pat>/); assert.match(String(mail.html), /Alex & Sam/); assert.match(String(mail.html), /<Rescue>/); assert.match(String(mail.html), /cid:flockpal-logo/); assert.equal(mail.attachments?.length, 1); assert.match(mail.text, /Sign in to FlockPal using pat@example.test/); assert.match(mail.text, /cannot remove birds/); assert.match(mail.text, /flock switcher/); assert.match(String(mail.html), /href="https:\/\/flockpal.test\/"/); }); test('invitation describes each assigned role and prevents multiline subjects', async () => { for (const role of ['viewer', 'caregiver', 'assistant', 'owner'] as const) { const mail = await buildWorkspaceInviteEmail({ ...input, role, flockName: 'Rescue\r\nFlock' }); assert.doesNotMatch(mail.subject, /[\r\n]/); assert.ok(mail.text.includes(role.charAt(0).toUpperCase() + role.slice(1))); if (role === 'viewer') assert.match(mail.text, /cannot edit records/); if (role === 'assistant') assert.match(mail.text, /remove and transfer birds/); if (role === 'owner') assert.match(mail.text, /does not change the billing owner/); } });