import { describe, it, expect } from 'vitest';
import { Email } from '../value-objects/email.vo';

describe('Email Value Object', () => {
  it('should create a valid email', () => {
    const result = Email.create('Test@Example.com');
    expect(result.isOk).toBe(true);
    expect(result.unwrap().value).toBe('test@example.com');
  });

  it('should reject an invalid email', () => {
    const result = Email.create('invalid-email');
    expect(result.isErr).toBe(true);
    expect(result.unwrapErr()).toBe('Email không hợp lệ');
  });

  it('should trim whitespace', () => {
    const result = Email.create('  user@test.com  ');
    expect(result.isOk).toBe(true);
    expect(result.unwrap().value).toBe('user@test.com');
  });

  it('should check equality', () => {
    const a = Email.create('user@test.com').unwrap();
    const b = Email.create('USER@TEST.COM').unwrap();
    expect(a.equals(b)).toBe(true);
  });
});
