import { describe, it, expect } from 'vitest';
import { validateEmail } from './validation';

describe('validateEmail', () => {
  it('should return valid for a valid email', () => {
    const result = validateEmail('test@example.com');
    expect(result.valid).toBe(true);
    expect(result.message).toBeUndefined();
  });

  it('should return invalid for empty email', () => {
    const result = validateEmail('');
    expect(result.valid).toBe(false);
    expect(result.message).toBe('Email is required');
  });

  it('should return invalid for email without @', () => {
    const result = validateEmail('invalid-email');
    expect(result.valid).toBe(false);
    expect(result.message).toBe('Invalid email format');
  });

  it('should return invalid for email without domain', () => {
    const result = validateEmail('test@');
    expect(result.valid).toBe(false);
    expect(result.message).toBe('Invalid email format');
  });

  it('should return invalid for email without TLD', () => {
    const result = validateEmail('test@example');
    expect(result.valid).toBe(false);
    expect(result.message).toBe('Invalid email format');
  });

  it('should return invalid for email longer than 254 characters', () => {
    const longEmail = `${'a'.repeat(250)}@example.com`;
    const result = validateEmail(longEmail);
    expect(result.valid).toBe(false);
    expect(result.message).toBe('Email is too long');
  });

  it('should return valid for email with special characters', () => {
    const result = validateEmail('test+alias@example.com');
    expect(result.valid).toBe(true);
  });

  it('should return valid for email with dots', () => {
    const result = validateEmail('first.last@example.com');
    expect(result.valid).toBe(true);
  });

  it('should return valid for email with subdomain', () => {
    const result = validateEmail('test@sub.example.com');
    expect(result.valid).toBe(true);
  });
});
