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

Function TestWebhookUpdate

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

Source from the content-addressed store, hash-verified

471}
472
473func TestWebhookUpdate(t *testing.T) {
474 s := makeTestServer(t)
475
476 // Create a user first
477 addRequest := newRequest("1", "admin.users.add", map[string]interface{}{
478 "adminToken": "test-admin-token",
479 "name": "WebhookUser",
480 "token": "webhook-token",
481 }).toJSON(t)
482 executeRequest(t, s, addRequest)
483
484 // Update webhook to subscribe to events
485 updateRequest := newRequest("2", "webhook.update", map[string]interface{}{
486 "token": "webhook-token",
487 "events": []string{"Message", "Connected"},
488 "active": true,
489 }).toJSON(t)
490 updateResponse := executeRequest(t, s, updateRequest)
491
492 expectedUpdate := map[string]interface{}{
493 "jsonrpc": "2.0",
494 "id": "2",
495 }
496 if diff := compareJSON(expectedUpdate, updateResponse); diff != "" {
497 t.Errorf("Update response mismatch:\n%s", diff)
498 }
499
500 // Verify the update worked by getting webhook config
501 getRequest := newRequest("3", "webhook.get", map[string]interface{}{
502 "token": "webhook-token",
503 }).toJSON(t)
504 getResponse := executeRequest(t, s, getRequest)
505
506 expectedGet := map[string]interface{}{
507 "jsonrpc": "2.0",
508 "id": "3",
509 }
510 if diff := compareJSON(expectedGet, getResponse); diff != "" {
511 t.Errorf("Get response mismatch:\n%s", diff)
512 }
513
514 // Check events are set
515 data := getResponse["result"].(map[string]interface{})
516 subscribe := data["subscribe"].([]interface{})
517 if len(subscribe) != 2 {
518 t.Errorf("Expected 2 subscribed events, got %d: %v", len(subscribe), subscribe)
519 }
520}
521
522func TestWebhookSet(t *testing.T) {
523 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