import { describe, it, expect } from 'vitest';

import { crmWelcomeEmail } from '@/lib/email/templates/crm-welcome';

describe('crmWelcomeEmail', () => {
  it('is a unique welcome email (not a password-reset) carrying the set-password link', async () => {
    const link = 'https://crm.example.com/set-password#token=abc123';
    const { subject, html, text } = await crmWelcomeEmail({
      link,
      recipientName: 'Jane Doe',
      appName: 'Port Nimara CRM',
    });

    // Distinct welcome framing, not the reset-password copy.
    expect(subject.toLowerCase()).toContain('welcome');
    expect(subject.toLowerCase()).not.toContain('reset');
    // No accidental double "CRM CRM" when the app name already carries it.
    expect(subject).not.toContain('CRM CRM');

    // Greets the recipient and drives them to set their password.
    expect(html).toContain('Jane Doe');
    expect(html).toContain('set-password');
    expect(html).toContain('abc123');
    expect(text).toContain(link);
  });

  it('falls back to a generic greeting when no name is given', async () => {
    const { html } = await crmWelcomeEmail({
      link: 'https://crm.example.com/set-password#token=xyz',
      appName: 'Port Nimara CRM',
    });
    expect(html.toLowerCase()).toContain('welcome');
  });
});
