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

// Mock the email sending function
const mockSendEmail = vi.fn().mockResolvedValue({ success: true });

describe('Forgot Password Email', () => {
  it('should construct email with correct parameters', async () => {
    const email = 'user@example.com';
    const resetToken = 'test-reset-token-abc123';
    const baseUrl = 'https://llmhosts.com';

    const params = {
      to: email,
      subject: 'Reset your LLMHosts password',
      resetUrl: `${baseUrl}/auth/reset-password?token=${resetToken}`,
    };

    await mockSendEmail(params);

    expect(mockSendEmail).toHaveBeenCalledWith(
      expect.objectContaining({
        to: email,
        subject: expect.stringContaining('Reset'),
        resetUrl: expect.stringContaining(resetToken),
      }),
    );
  });

  it('should include secure token in reset URL', () => {
    const token = 'abc123def456';
    const url = `https://llmhosts.com/auth/reset-password?token=${token}`;

    expect(url).toContain(token);
    expect(url).toMatch(/^https:\/\//);
  });

  it('should not expose internal paths in email', () => {
    const emailBody = 'Click the link below to reset your password.';

    expect(emailBody).not.toContain('/api/');
    expect(emailBody).not.toContain('localhost');
    expect(emailBody).not.toContain('127.0.0.1');
  });
});
