arreglos varios antes de la primera version en produccion
This commit is contained in:
+32
-18
@@ -23,6 +23,7 @@ func TestEaRouteAllowed(t *testing.T) {
|
||||
{"GET", "/ea-api/v1/services", true},
|
||||
{"GET", "/ea-api/v1/availabilities", true},
|
||||
{"GET", "/ea-api/v1/providers/1", true},
|
||||
{"GET", "/ea-api/v1/settings/company_working_plan", true},
|
||||
|
||||
// Bloqueadas: clientes y citas ya NO pasan por el proxy
|
||||
{"GET", "/ea-api/v1/customers", false},
|
||||
@@ -34,6 +35,8 @@ func TestEaRouteAllowed(t *testing.T) {
|
||||
{"GET", "/ea-api/v1/providers", false}, // listar todos
|
||||
{"GET", "/ea-api/v1/providers/abc", false}, // id no numérico
|
||||
{"GET", "/ea-api/v1/settings", false},
|
||||
{"GET", "/ea-api/v1/settings/email_footer", false}, // otros settings no
|
||||
{"POST", "/ea-api/v1/settings/company_working_plan", false},
|
||||
{"POST", "/ea-api/v1/services", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
@@ -43,22 +46,6 @@ func TestEaRouteAllowed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitName(t *testing.T) {
|
||||
cases := []struct{ in, first, last string }{
|
||||
{"", "", ""},
|
||||
{"Ana", "Ana", ""},
|
||||
{"Ana López", "Ana", "López"},
|
||||
{"Ana María López Gil", "Ana", "María López Gil"},
|
||||
{" Ana López ", "Ana", "López"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
f, l := splitName(c.in)
|
||||
if f != c.first || l != c.last {
|
||||
t.Errorf("splitName(%q) = (%q,%q), want (%q,%q)", c.in, f, l, c.first, c.last)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlexIntUnmarshal(t *testing.T) {
|
||||
var s struct {
|
||||
A flexInt `json:"a"`
|
||||
@@ -79,6 +66,7 @@ func TestFlexIntUnmarshal(t *testing.T) {
|
||||
// duración total y servicio principal en el servidor.
|
||||
func TestHandleBook(t *testing.T) {
|
||||
var gotAppt eaAppointment
|
||||
var gotCust eaCustomer
|
||||
var hits []string
|
||||
|
||||
mux := http.NewServeMux()
|
||||
@@ -96,6 +84,7 @@ func TestHandleBook(t *testing.T) {
|
||||
return
|
||||
}
|
||||
hits = append(hits, "POST customers")
|
||||
json.NewDecoder(r.Body).Decode(&gotCust)
|
||||
json.NewEncoder(w).Encode(eaCustomer{ID: 99})
|
||||
})
|
||||
mux.HandleFunc("/index.php/api/v1/appointments", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -109,7 +98,7 @@ func TestHandleBook(t *testing.T) {
|
||||
|
||||
ea := &eaClient{base: srv.URL, http: srv.Client()}
|
||||
|
||||
body := `{"nombre":"Ana López","email":"ana@x.com","telefono":"600","mensaje":"hola",
|
||||
body := `{"nombre":"Ana","apellidos":"López Gil","email":"ana@x.com","telefono":"600","mensaje":"hola",
|
||||
"providerId":1,"serviceIds":[1,2],"date":"2026-07-01","time":"10:00"}`
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/book", strings.NewReader(body))
|
||||
rec := httptest.NewRecorder()
|
||||
@@ -129,6 +118,10 @@ func TestHandleBook(t *testing.T) {
|
||||
if gotAppt.CustomerID != 99 || gotAppt.ProviderID != 1 || gotAppt.Status != "booked" {
|
||||
t.Errorf("appt = %+v", gotAppt)
|
||||
}
|
||||
// Nombre y apellidos viajan por separado hasta EA, sin adivinar cuál es cuál.
|
||||
if gotCust.FirstName != "Ana" || gotCust.LastName != "López Gil" {
|
||||
t.Errorf("cliente = %q %q, want \"Ana\" \"López Gil\"", gotCust.FirstName, gotCust.LastName)
|
||||
}
|
||||
if !strings.Contains(gotAppt.Notes, "Duración total: 75 min") ||
|
||||
!strings.Contains(gotAppt.Notes, "Servicios: Corte + Tinte") {
|
||||
t.Errorf("notes = %q", gotAppt.Notes)
|
||||
@@ -155,7 +148,7 @@ func TestHandleBookRejectsUnknownService(t *testing.T) {
|
||||
defer srv.Close()
|
||||
ea := &eaClient{base: srv.URL, http: srv.Client()}
|
||||
|
||||
body := `{"nombre":"Ana","email":"a@x.com","telefono":"600","providerId":1,"serviceIds":[999],"date":"2026-07-01","time":"10:00"}`
|
||||
body := `{"nombre":"Ana","apellidos":"López","email":"a@x.com","telefono":"600","providerId":1,"serviceIds":[999],"date":"2026-07-01","time":"10:00"}`
|
||||
rec := httptest.NewRecorder()
|
||||
handleBook(ea)(rec, httptest.NewRequest(http.MethodPost, "/api/book", strings.NewReader(body)))
|
||||
|
||||
@@ -166,3 +159,24 @@ func TestHandleBookRejectsUnknownService(t *testing.T) {
|
||||
t.Error("se creó una cita con un servicio inexistente")
|
||||
}
|
||||
}
|
||||
|
||||
// Sin apellidos ⇒ 400 sin llegar a llamar a EA.
|
||||
func TestHandleBookRequiresApellidos(t *testing.T) {
|
||||
called := false
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { called = true })
|
||||
srv := httptest.NewServer(mux)
|
||||
defer srv.Close()
|
||||
ea := &eaClient{base: srv.URL, http: srv.Client()}
|
||||
|
||||
body := `{"nombre":"Ana","email":"a@x.com","telefono":"600","providerId":1,"serviceIds":[1],"date":"2026-07-01","time":"10:00"}`
|
||||
rec := httptest.NewRecorder()
|
||||
handleBook(ea)(rec, httptest.NewRequest(http.MethodPost, "/api/book", strings.NewReader(body)))
|
||||
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Errorf("status = %d, want 400", rec.Code)
|
||||
}
|
||||
if called {
|
||||
t.Error("se llamó a EA con datos incompletos")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user