MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestHandleUpdateMe_ValidationErrors

Function TestHandleUpdateMe_ValidationErrors

internal/auth/auth_test.go:310–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

308}
309
310func TestHandleUpdateMe_ValidationErrors(t *testing.T) {
311 ua, _, token := setupUserAuth(t)
312
313 // Each case asserts that the validation gate fires and a 400 is
314 // returned BEFORE any DB write. The handler chooses to reject rather
315 // than normalize so a caller's exact bytes round-trip cleanly through
316 // /me on the next GET.
317 cases := []struct {
318 name string
319 body string
320 }{
321 {"empty string", `{"name":""}`},
322 {"leading whitespace", `{"name":" Jamie"}`},
323 {"trailing whitespace", `{"name":"Jamie "}`},
324 {"too long", `{"name":"` + strings.Repeat("a", 81) + `"}`},
325 {"missing name field", `{}`},
326 {"malformed JSON", `{not-json}`},
327 }
328 for _, tc := range cases {
329 t.Run(tc.name, func(t *testing.T) {
330 req := authedJSON("PATCH", "/api/auth/me", token, tc.body)
331 w := httptest.NewRecorder()
332 ua.HandleUpdateMe(w, req)
333 if w.Code != http.StatusBadRequest {
334 t.Errorf("status = %d, want 400; body=%s", w.Code, w.Body.String())
335 }
336 })
337 }
338}
339
340func TestHandleUpdateMe_MaxBoundary(t *testing.T) {
341 // 80 chars must succeed; 81 already covered by ValidationErrors.

Callers

nothing calls this directly

Calls 5

setupUserAuthFunction · 0.85
RunMethod · 0.80
HandleUpdateMeMethod · 0.80
authedJSONFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected