Skip to content

Commit 0eb4350

Browse files
committed
test(api/v2): assert admin project id via structured json
1 parent 1c2b2db commit 0eb4350

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

pkg/webtests/huma_admin_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package webtests
1818

1919
import (
20+
"encoding/json"
2021
"net/http"
2122
"testing"
2223

@@ -76,15 +77,25 @@ func TestHumaAdminProjects(t *testing.T) {
7677

7778
res := adminReq(t, e, http.MethodGet, "/api/v2/admin/projects", admin, "")
7879
require.Equal(t, http.StatusOK, res.Code, res.Body.String())
79-
body := res.Body.String()
80+
8081
// 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+
}
8394
// Project 6 is owned by user6, not shared with user1 — the admin list
8495
// 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)
8697
// 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)
8899
})
89100

90101
t.Run("unauthenticated caller gets 401", func(t *testing.T) {

0 commit comments

Comments
 (0)