MCPcopy
hub / github.com/dosco/graphjin / TestResponseProcessor_NestedObjects

Function TestResponseProcessor_NestedObjects

core/cache_response_test.go:447–523  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

445}
446
447func TestResponseProcessor_NestedObjects(t *testing.T) {
448 // Create qcode with nested selection: users -> posts
449 qc := &qcode.QCode{
450 Selects: []qcode.Select{
451 {
452 Field: qcode.Field{
453 ID: 0,
454 ParentID: -1,
455 FieldName: "users",
456 },
457 Table: "users",
458 Ti: sdata.DBTable{Name: "users"},
459 Children: []int32{1},
460 },
461 {
462 Field: qcode.Field{
463 ID: 1,
464 ParentID: 0,
465 FieldName: "posts",
466 },
467 Table: "posts",
468 Ti: sdata.DBTable{Name: "posts"},
469 },
470 },
471 }
472 rp := NewResponseProcessor(qc)
473
474 input := []byte(`{"data": {"users": {
475 "id": 1,
476 "name": "John",
477 "__gj_id": 1,
478 "posts": [
479 {"id": 10, "title": "First Post", "__gj_id": 10},
480 {"id": 11, "title": "Second Post", "__gj_id": 11}
481 ]
482 }}}`)
483
484 cleaned, refs, err := rp.ProcessForCache(input)
485 if err != nil {
486 t.Errorf("unexpected error: %v", err)
487 }
488
489 // Should have extracted 3 refs (1 user + 2 posts)
490 if len(refs) != 3 {
491 t.Errorf("expected 3 refs, got %d", len(refs))
492 }
493
494 // Count by table
495 tableCount := make(map[string]int)
496 for _, ref := range refs {
497 tableCount[ref.Table]++
498 }
499 if tableCount["users"] != 1 {
500 t.Errorf("expected 1 users ref, got %d", tableCount["users"])
501 }
502 if tableCount["posts"] != 2 {
503 t.Errorf("expected 2 posts refs, got %d", tableCount["posts"])
504 }

Callers

nothing calls this directly

Calls 2

ProcessForCacheMethod · 0.95
NewResponseProcessorFunction · 0.85

Tested by

no test coverage detected