e6c493b756
- Contatti: nome, cognome, telefono e mail resi obbligatori (validazione client + server); il form del footer ora include cognome e telefono. - Home hero: rimossa la foto (file conservato su disco), fascia ridotta da 100vh a padding contenuto, testo allargato. - Menu: la voce "Promo 2 (test)" è visibile solo agli admin loggati. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { validateContact } from '../src/lib/contact';
|
|
|
|
describe('validateContact', () => {
|
|
const good = { firstName: 'Mario', lastName: 'Rossi', phone: '3331234567', email: 'mario@example.com', message: 'Ciao, vorrei informazioni.' };
|
|
|
|
it('accetta payload valido', () => {
|
|
const r = validateContact(good);
|
|
expect(r.ok).toBe(true);
|
|
if (r.ok) {
|
|
expect(r.value.lastName).toBe('Rossi');
|
|
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, lastName: ' ' }).ok).toBe(false);
|
|
expect(validateContact({ ...good, phone: '' }).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);
|
|
});
|
|
});
|