MCPcopy
hub / github.com/pocketbase/pocketbase / TestEventJSON

Function TestEventJSON

tools/router/event_test.go:411–452  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

409}
410
411func TestEventJSON(t *testing.T) {
412 body := map[string]any{"a": 123, "b": 456, "c": "test"}
413 expectedPickedBody := `{"a":123,"c":"test"}` + "\n"
414 expectedFullBody := `{"a":123,"b":456,"c":"test"}` + "\n"
415
416 scenarios := []testResponseWriteScenario[any]{
417 {
418 name: "no explicit content-type",
419 status: 200,
420 headers: nil,
421 body: body,
422 expectedStatus: 200,
423 expectedHeaders: map[string]string{"content-type": "application/json"},
424 expectedBody: expectedPickedBody,
425 },
426 {
427 name: "with explicit content-type (200)",
428 status: 200,
429 headers: map[string]string{"content-type": "application/test"},
430 body: body,
431 expectedStatus: 200,
432 expectedHeaders: map[string]string{"content-type": "application/test"},
433 expectedBody: expectedPickedBody,
434 },
435 {
436 name: "with explicit content-type (400)", // no fields picker
437 status: 400,
438 headers: map[string]string{"content-type": "application/test"},
439 body: body,
440 expectedStatus: 400,
441 expectedHeaders: map[string]string{"content-type": "application/test"},
442 expectedBody: expectedFullBody,
443 },
444 }
445
446 for _, s := range scenarios {
447 testEventResponseWrite(t, s, func(e *router.Event) error {
448 e.Request.URL.RawQuery = "fields=a,c" // ensures that the picker is invoked
449 return e.JSON(s.status, s.body)
450 })
451 }
452}
453
454func TestEventXML(t *testing.T) {
455 scenarios := []testResponseWriteScenario[string]{

Callers

nothing calls this directly

Calls 2

testEventResponseWriteFunction · 0.85
JSONMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…