Fix pagination test response parsing
The pagination tests were incorrectly parsing the API response. The API
returns data wrapped in a {"data": [...]} structure, but the tests were
expecting a direct array. This caused tests to fail silently when
json.Decode couldn't match the response structure.
Changed response parsing to correctly extract the "data" field before
asserting on array length.
This commit is contained in:
@@ -334,11 +334,12 @@ func TestMediaItemsPagination(t *testing.T) {
|
||||
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
var response []map[string]interface{}
|
||||
var response map[string]interface{}
|
||||
json.NewDecoder(resp.Body).Decode(&response)
|
||||
data := response["data"].([]interface{})
|
||||
|
||||
// Should get 2 items
|
||||
assert.Equal(t, 2, len(response))
|
||||
assert.Equal(t, 2, len(data))
|
||||
})
|
||||
|
||||
t.Run("Pagination with offset", func(t *testing.T) {
|
||||
@@ -352,11 +353,12 @@ func TestMediaItemsPagination(t *testing.T) {
|
||||
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
var response []map[string]interface{}
|
||||
var response map[string]interface{}
|
||||
json.NewDecoder(resp.Body).Decode(&response)
|
||||
data := response["data"].([]interface{})
|
||||
|
||||
// Should get 2 items starting from offset 2
|
||||
assert.Equal(t, 2, len(response))
|
||||
assert.Equal(t, 2, len(data))
|
||||
})
|
||||
|
||||
t.Run("Negative limit should fail", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user