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

import { isDisposableEmail, validateEmail } from '@core/identity/domain/value-objects/EmailAddress';

describe('identity-domain email validation', () => {
  it('accepts a valid email and normalizes it', () => {
    const result = validateEmail('  USER@example.com  ');

    expect(result.success).toBe(true);
    expect(result.email).toBe('user@example.com');
    expect(result.error).toBeUndefined();
  });

  it('rejects an invalid email format', () => {
    const result = validateEmail('not-an-email');

    expect(result.success).toBe(false);
    expect(result.email).toBeUndefined();
    expect(result.error).toBeTypeOf('string');
  });

  it('rejects an email that is too short', () => {
    const result = validateEmail('a@b');

    expect(result.success).toBe(false);
    expect(result.error).toContain('too short');
  });

  it('detects disposable email domains', () => {
    expect(isDisposableEmail('foo@tempmail.com')).toBe(true);
    expect(isDisposableEmail('bar@mailinator.com')).toBe(true);
    expect(isDisposableEmail('user@example.com')).toBe(false);
  });
});