MCPcopy Create free account
hub / github.com/asternic/wuzapi / TestAdminUsersGet

Function TestAdminUsersGet

stdio_test.go:94–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestAdminUsersGet(t *testing.T) {
95 s := makeTestServer(t)
96
97 // First add a user
98 addRequest := newRequest("1", "admin.users.add", map[string]interface{}{
99 "adminToken": "test-admin-token",
100 "name": "Bob",
101 "token": "bob-token-456",
102 }).toJSON(t)
103 addResponse := executeRequest(t, s, addRequest)
104
105 expectedAdd := map[string]interface{}{
106 "jsonrpc": "2.0",
107 "id": "1",
108 }
109 if diff := compareJSON(expectedAdd, addResponse); diff != "" {
110 t.Errorf("Add response mismatch:\n%s", diff)
111 }
112
113 // Extract the userId from the add response
114 addData := addResponse["result"].(map[string]interface{})
115 userId := addData["id"].(string)
116
117 // Now get the specific user
118 getRequest := newRequest("2", "admin.users.get", map[string]interface{}{
119 "adminToken": "test-admin-token",
120 "userId": userId,
121 }).toJSON(t)
122 getResponse := executeRequest(t, s, getRequest)
123
124 expectedGet := map[string]interface{}{
125 "jsonrpc": "2.0",
126 "id": "2",
127 }
128 if diff := compareJSON(expectedGet, getResponse); diff != "" {
129 t.Errorf("Get response mismatch:\n%s", diff)
130 }
131
132 // Verify the user data
133 users := getResponse["result"].([]interface{})
134 if len(users) != 1 {
135 t.Fatalf("Expected 1 user, got %d", len(users))
136 }
137
138 user := users[0].(map[string]interface{})
139 expectedUser := map[string]interface{}{
140 "name": "Bob",
141 "token": "bob-token-456",
142 }
143 if diff := compareJSON(expectedUser, user); diff != "" {
144 t.Errorf("User data mismatch:\n%s", diff)
145 }
146}
147
148func TestAdminUsersDelete(t *testing.T) {
149 s := makeTestServer(t)

Callers

nothing calls this directly

Calls 5

makeTestServerFunction · 0.85
newRequestFunction · 0.85
executeRequestFunction · 0.85
compareJSONFunction · 0.85
toJSONMethod · 0.80

Tested by

no test coverage detected