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

Function TestResponseProcessor_Array

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

Source from the content-addressed store, hash-verified

391}
392
393func TestResponseProcessor_Array(t *testing.T) {
394 qc := &qcode.QCode{
395 Selects: []qcode.Select{
396 {
397 Field: qcode.Field{
398 ID: 0,
399 ParentID: -1,
400 FieldName: "products",
401 },
402 Table: "products",
403 Ti: sdata.DBTable{Name: "products"},
404 },
405 },
406 }
407 rp := NewResponseProcessor(qc)
408
409 input := []byte(`{"data": {"products": [
410 {"id": 1, "name": "Widget", "__gj_id": 1},
411 {"id": 2, "name": "Gadget", "__gj_id": 2},
412 {"id": 3, "name": "Gizmo", "__gj_id": 3}
413 ]}}`)
414
415 cleaned, refs, err := rp.ProcessForCache(input)
416 if err != nil {
417 t.Errorf("unexpected error: %v", err)
418 }
419
420 // Should have extracted three refs
421 if len(refs) != 3 {
422 t.Errorf("expected 3 refs, got %d", len(refs))
423 }
424
425 // Verify all refs are for products table
426 for i, ref := range refs {
427 if ref.Table != "products" {
428 t.Errorf("ref[%d] expected table 'products', got %q", i, ref.Table)
429 }
430 }
431
432 // Verify __gj_id removed from all items
433 var result map[string]interface{}
434 if err := json.Unmarshal(cleaned, &result); err != nil {
435 t.Errorf("failed to parse cleaned response: %v", err)
436 }
437 dataMap := result["data"].(map[string]interface{})
438 products := dataMap["products"].([]interface{})
439 for i, p := range products {
440 prod := p.(map[string]interface{})
441 if _, hasGjId := prod["__gj_id"]; hasGjId {
442 t.Errorf("products[%d] should not have __gj_id", i)
443 }
444 }
445}
446
447func TestResponseProcessor_NestedObjects(t *testing.T) {
448 // Create qcode with nested selection: users -> posts

Callers

nothing calls this directly

Calls 2

ProcessForCacheMethod · 0.95
NewResponseProcessorFunction · 0.85

Tested by

no test coverage detected