package services import ( "testing" ) func TestExtractEmailSimple(t *testing.T) { tests := []struct { input string want string }{ {"user@example.com", "user@example.com"}, {"", "user@example.com"}, {"John Doe ", "john@example.com"}, {"\"John Doe\" ", "john@example.com"}, {" spaced@example.com ", "spaced@example.com"}, {"", ""}, {"", "onlybrackets"}, } for _, tt := range tests { got := ExtraerEmail(tt.input) if got != tt.want { t.Errorf("ExtraerEmail(%q) = %q, want %q", tt.input, got, tt.want) } } } func TestExtractNameSimple(t *testing.T) { tests := []struct { input string want string }{ {"John Doe ", "John Doe"}, {"", ""}, {"user@example.com", ""}, {" Spaces Here ", "Spaces Here"}, {"\"Quoted Name\" ", "\"Quoted Name\""}, {"", ""}, } for _, tt := range tests { got := ExtraerNombre(tt.input) if got != tt.want { t.Errorf("ExtraerNombre(%q) = %q, want %q", tt.input, got, tt.want) } } } func TestExtractEmailRealWorld(t *testing.T) { inputs := []struct { full string mail string name string }{ {"María López ", "maria@example.com", "María López"}, {"soporte@u-s.app", "soporte@u-s.app", ""}, {"Cliente Final ", "cliente+tag@dominio.co", "Cliente Final"}, {"", "", ""}, } for _, tt := range inputs { gotMail := ExtraerEmail(tt.full) gotName := ExtraerNombre(tt.full) if gotMail != tt.mail { t.Errorf("ExtraerEmail(%q) = %q, want %q", tt.full, gotMail, tt.mail) } if gotName != tt.name { t.Errorf("ExtraerNombre(%q) = %q, want %q", tt.full, gotName, tt.name) } } } func TestExtractEmailEdgeCases(t *testing.T) { // Formato RFC 5322 con nombre y ángulos if got := ExtraerEmail("a"); got != "b@c.com" { t.Errorf("ExtraerEmail('a') = %q, want 'b@c.com'", got) } // Múltiples brackets — usa el último par if got := ExtraerEmail(""); got != "b@c.com" { t.Errorf("ExtraerEmail('') = %q, want 'b@c.com'", got) } } func TestResumirTextoSoporteCortoNoLlamaALaIA(t *testing.T) { // Sin base de datos, cualquier llamada a la IA explota: que este caso pase // es la prueba de que un correo corto no la usa. corto := "Hola, no me llega la factura de marzo. Gracias." if got := ResumirTextoSoporte(corto); got != corto { t.Errorf("ResumirTextoSoporte devolvió %q, esperaba el texto tal cual", got) } if got := ResumirTextoSoporte(" " + corto + "\n"); got != corto { t.Errorf("no recortó los espacios: %q", got) } }