import { describe, it, expect } from 'vitest';
import { validateContact } from '../src/lib/contact';

describe('validateContact', () => {
  const good = { firstName: 'Mario', email: 'mario@example.com', message: 'Ciao, vorrei informazioni.' };

  it('accetta payload valido e normalizza i campi opzionali', () => {
    const r = validateContact(good);
    expect(r.ok).toBe(true);
    if (r.ok) {
      expect(r.value.lastName).toBe('');
      expect(r.value.email).toBe('mario@example.com');
    }
  });

  it('rifiuta email non valida', () => {
    expect(validateContact({ ...good, email: 'non-email' }).ok).toBe(false);
  });

  it('rifiuta campi obbligatori mancanti o vuoti', () => {
    expect(validateContact({ ...good, firstName: ' ' }).ok).toBe(false);
    expect(validateContact({ ...good, message: '' }).ok).toBe(false);
    expect(validateContact(null).ok).toBe(false);
  });

  it('rifiuta honeypot compilato', () => {
    expect(validateContact({ ...good, website: 'spam.com' }).ok).toBe(false);
  });

  it('rifiuta messaggi oltre 5000 caratteri', () => {
    expect(validateContact({ ...good, message: 'x'.repeat(5001) }).ok).toBe(false);
  });
});
