package services import ( "net/mail" "strings" "testing" ) // Los correos masivos se descartan por sus propios encabezados: este test pasa // sin base de datos ni IA, que es justamente la prueba de que no las usa. func TestClasificarCorreoAutomaticoNoGastaIA(t *testing.T) { cl := ClasificarCorreoSoporte(CorreoSoporte{ From: "news@marketing.com", Subject: "20% off", Texto: "Oferta", Automatico: true, }, "") if cl.EsSoporte { t.Error("un correo masivo no debería contar como soporte") } if cl.Categoria != "newsletter" { t.Errorf("Categoria = %q", cl.Categoria) } } func TestEsCorreoAutomatico(t *testing.T) { casos := []struct { nombre string cabeceras string want bool }{ {"newsletter", "List-Unsubscribe: \r\n", true}, {"lista", "List-Id: \r\n", true}, {"bulk", "Precedence: bulk\r\n", true}, {"auto-generado", "Auto-Submitted: auto-generated\r\n", true}, {"auto-submitted no", "Auto-Submitted: no\r\n", false}, {"persona", "", false}, } for _, c := range casos { msg, err := mail.ReadMessage(strings.NewReader( "From: a@b.com\r\nSubject: x\r\n" + c.cabeceras + "\r\ncuerpo\r\n")) if err != nil { t.Fatalf("%s: %v", c.nombre, err) } if got := esCorreoAutomatico(msg.Header); got != c.want { t.Errorf("%s: esCorreoAutomatico = %v, want %v", c.nombre, got, c.want) } } } func TestSoloJSON(t *testing.T) { casos := map[string]string{ "```json\n{\"es_soporte\":true}\n```": `{"es_soporte":true}`, "Claro:\n{\"es_soporte\":false}\nEspero...": `{"es_soporte":false}`, `{"es_soporte":true}`: `{"es_soporte":true}`, } for in, want := range casos { if got := soloJSON(in); got != want { t.Errorf("soloJSON(%q) = %q, want %q", in, got, want) } } } func TestClasificarNormalizaPrioridad(t *testing.T) { // El correo automático corta antes de llamar a la IA, así que es el único // camino que se puede probar sin base de datos — y ahí la prioridad tiene // que salir puesta igual. cl := ClasificarCorreoSoporte(CorreoSoporte{ From: "news@x.com", Subject: "promo", Automatico: true, }, "") if cl.Prioridad != "baja" { t.Errorf("Prioridad = %q, want baja", cl.Prioridad) } }