-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebhooks_test.go
95 lines (74 loc) · 2.23 KB
/
webhooks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package dev
import (
"os"
"strconv"
"testing"
)
func TestGetWebhooks(t *testing.T) {
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
webhooks, err := c.GetWebhooks()
if err != nil {
t.Errorf("Error fetching webhooks: %s", err.Error())
}
for _, v := range webhooks {
if v.TypeOf != "webhook_endpoint" {
t.Error("Expected result to include webhooks registered by the user")
}
}
}
func TestCreateWebhook(t *testing.T) {
t.Skip()
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
targetURL := os.Getenv("TEST_WEBHOOK_TARGET_URL")
payload := WebhookBodySchema{}
payload.WebhookEndpoint.TargetURL = targetURL
payload.WebhookEndpoint.Source = "DEV"
payload.WebhookEndpoint.Events = []string{"article_created"}
webhook, err := c.CreateWebhook(payload)
if err != nil {
t.Errorf("Error trying to create webhook: %s", err.Error())
}
if webhook.TypeOf != "webhook_endpoint" {
t.Errorf("Expected 'type_of' field to be 'webhook_endpoint', instead got %s", webhook.TypeOf)
}
if webhook.Events[0] != "article_created" {
t.Errorf("Expected webhook events to include 'article_created', instead got %s", webhook.Events[0])
}
}
func TestGetWebhookByID(t *testing.T) {
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
webhookID := os.Getenv("TEST_WEBHOOK_ID")
webhook, err := c.GetWebhookByID(webhookID)
if err != nil {
t.Errorf("Error fetching webhook: %s", err.Error())
}
if webhook.TypeOf != "webhook_endpoint" {
t.Errorf("Expected 'type_of' field to be 'webhook_endpoint', instead got '%s'", webhook.TypeOf)
}
expected, err := strconv.Atoi(webhookID)
if err != nil {
t.Errorf("Error converting string to int: %s", err.Error())
}
if webhook.ID != int64(expected) {
t.Errorf("Expected webhook id to be '%d', instead got '%d'", expected, webhook.ID)
}
}
func TestDeleteWebhook(t *testing.T) {
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
webhookID := os.Getenv("TEST_WEBHOOK_ID")
if err := c.DeleteWebhook(webhookID); err != nil {
t.Errorf("Error deleting webhook: %s", err.Error())
}
}