|
17 | 17 | package webtests |
18 | 18 |
|
19 | 19 | import ( |
| 20 | + "encoding/json" |
20 | 21 | "net/http" |
21 | 22 | "testing" |
22 | 23 |
|
@@ -76,15 +77,25 @@ func TestHumaAdminProjects(t *testing.T) { |
76 | 77 |
|
77 | 78 | res := adminReq(t, e, http.MethodGet, "/api/v2/admin/projects", admin, "") |
78 | 79 | require.Equal(t, http.StatusOK, res.Code, res.Body.String()) |
79 | | - body := res.Body.String() |
| 80 | + |
80 | 81 | // v2 wraps lists in the Paginated envelope. |
81 | | - assert.Contains(t, body, `"items":`) |
82 | | - assert.Contains(t, body, `"total":`) |
| 82 | + var envelope struct { |
| 83 | + Items []struct { |
| 84 | + ID int64 `json:"id"` |
| 85 | + } `json:"items"` |
| 86 | + Total int64 `json:"total"` |
| 87 | + } |
| 88 | + require.NoError(t, json.Unmarshal(res.Body.Bytes(), &envelope)) |
| 89 | + |
| 90 | + ids := make(map[int64]bool, len(envelope.Items)) |
| 91 | + for _, item := range envelope.Items { |
| 92 | + ids[item.ID] = true |
| 93 | + } |
83 | 94 | // Project 6 is owned by user6, not shared with user1 — the admin list |
84 | 95 | // surfaces it regardless of ownership. |
85 | | - assert.Contains(t, body, `"id":6`) |
| 96 | + assert.True(t, ids[6], "expected project 6 in the admin list, got items %v", ids) |
86 | 97 | // Project 22 is archived; the admin list includes archived projects. |
87 | | - assert.Contains(t, body, `"id":22`) |
| 98 | + assert.True(t, ids[22], "expected archived project 22 in the admin list, got items %v", ids) |
88 | 99 | }) |
89 | 100 |
|
90 | 101 | t.Run("unauthenticated caller gets 401", func(t *testing.T) { |
|
0 commit comments