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

Function TestAdminUsersAddAndList

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

Source from the content-addressed store, hash-verified

37}
38
39func TestAdminUsersAddAndList(t *testing.T) {
40 s := makeTestServer(t)
41
42 // First, add a user
43 addRequest := newRequest("1", "admin.users.add", map[string]interface{}{
44 "adminToken": "test-admin-token",
45 "name": "Alice",
46 "token": "alice-token-123",
47 }).toJSON(t)
48 addResponse := executeRequest(t, s, addRequest)
49
50 expectedAdd := map[string]interface{}{
51 "jsonrpc": "2.0",
52 "id": "1",
53 }
54 if diff := compareJSON(expectedAdd, addResponse); diff != "" {
55 t.Errorf("Add response mismatch:\n%s", diff)
56 }
57 if addResponse["error"] != nil {
58 t.Fatalf("Failed to add user: %v", addResponse["error"])
59 }
60
61 // Now list users to verify the user was added
62 listRequest := newRequest("2", "admin.users.list", map[string]interface{}{
63 "adminToken": "test-admin-token",
64 }).toJSON(t)
65 listResponse := executeRequest(t, s, listRequest)
66
67 expectedList := map[string]interface{}{
68 "jsonrpc": "2.0",
69 "id": "2",
70 }
71 if diff := compareJSON(expectedList, listResponse); diff != "" {
72 t.Errorf("List response mismatch:\n%s", diff)
73 }
74 if listResponse["error"] != nil {
75 t.Fatalf("List request failed: %v", listResponse["error"])
76 }
77
78 // Verify the user appears in the list with correct data
79 users := listResponse["result"].([]interface{})
80 if len(users) != 1 {
81 t.Fatalf("Expected 1 user, got %d", len(users))
82 }
83
84 user := users[0].(map[string]interface{})
85 expectedUser := map[string]interface{}{
86 "name": "Alice",
87 "token": "alice-token-123",
88 }
89 if diff := compareJSON(expectedUser, user); diff != "" {
90 t.Errorf("User data mismatch:\n%s", diff)
91 }
92}
93
94func TestAdminUsersGet(t *testing.T) {
95 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