package wire_test import ( "encoding/json" "testing" "s1d3sw1ped/robinhood-agentic-mcp/internal/wire" ) func TestUnmarshalRows_objectAndArray(t *testing.T) { t.Parallel() type row struct { ID string `json:"id"` } rows, next, err := wire.UnmarshalRows[row](json.RawMessage(`{"data":{"positions":[{"id":"a"}],"next_cursor":"c2"}}`), "positions", "results") if err != nil { t.Fatal(err) } if len(rows) != 1 || rows[0].ID != "a" || next != "c2" { t.Fatalf("%+v %q", rows, next) } rows, next, err = wire.UnmarshalRows[row](json.RawMessage(`[{"id":"b"}]`), "positions") if err != nil { t.Fatal(err) } if len(rows) != 1 || rows[0].ID != "b" || next != "" { t.Fatalf("%+v %q", rows, next) } rows, next, err = wire.UnmarshalRows[row](json.RawMessage(`{"results":{"id":"one"},"next":"https://x/?cursor=n3"}`), "positions", "results") if err != nil { t.Fatal(err) } if len(rows) != 1 || rows[0].ID != "one" || next != "n3" { t.Fatalf("%+v %q", rows, next) } } func TestCursor(t *testing.T) { t.Parallel() if wire.Cursor("https://x/y?cursor=abc", "") != "abc" { t.Fatal("url") } if wire.Cursor("rawtok", "pref") != "pref" { t.Fatal("pref") } if wire.Cursor("rawtok", "") != "rawtok" { t.Fatal("bare") } }