-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathemails_webhooks_service_test.go
110 lines (99 loc) · 2.83 KB
/
emails_webhooks_service_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package sendpulse_sdk_go
import (
"context"
"fmt"
"net/http"
)
func (suite *SendpulseTestSuite) TestEmailsService_WebhooksService_List() {
suite.mux.HandleFunc("/v2/email-service/webhook", func(w http.ResponseWriter, r *http.Request) {
suite.Equal(http.MethodGet, r.Method)
fmt.Fprintf(w, `{
"success": true,
"data": [
{
"id": 162242,
"user_id": 7043663,
"url": "https://webhook.site/577e5242-bb27-4baf-8ea7-70baa6344f68",
"action": "unsubscribe"
},
{
"id": 162241,
"user_id": 7043663,
"url": "https://webhook.site/577e5242-bb27-4baf-8ea7-70baa6344f68",
"action": "open"
}
]
}`)
})
webhooks, err := suite.client.Emails.Webhooks.GetWebhooks(context.Background())
suite.NoError(err)
suite.Equal(2, len(webhooks))
}
func (suite *SendpulseTestSuite) TestEmailsService_WebhooksService_Get() {
suite.mux.HandleFunc("/v2/email-service/webhook/1", func(w http.ResponseWriter, r *http.Request) {
suite.Equal(http.MethodGet, r.Method)
fmt.Fprintf(w, `{
"success": true,
"data": {
"id": 162242,
"user_id": 7043663,
"url": "https://webhook.site/577e5242-bb27-4baf-8ea7-70baa6344f68",
"action": "unsubscribe"
}
}`)
})
webhook, err := suite.client.Emails.Webhooks.GetWebhook(context.Background(), 1)
suite.NoError(err)
suite.Equal(162242, webhook.ID)
}
func (suite *SendpulseTestSuite) TestEmailsService_WebhooksService_Create() {
suite.mux.HandleFunc("/v2/email-service/webhook/", func(w http.ResponseWriter, r *http.Request) {
suite.Equal(http.MethodPost, r.Method)
fmt.Fprintf(w, `{
"success": true,
"data": [
{
"id": 162242,
"user_id": 7043663,
"url": "https://sendpulse.com",
"action": "unsubscribe"
},
{
"id": 162241,
"user_id": 7043663,
"url": "https://sendpulse.com",
"action": "open"
}
]
}`)
})
webhooks, err := suite.client.Emails.Webhooks.CreateWebhook(context.Background(), []string{"unsubscribe", "open"}, "https://sendpulse.com")
suite.NoError(err)
suite.Equal(2, len(webhooks))
}
func (suite *SendpulseTestSuite) TestEmailsService_WebhooksService_Update() {
suite.mux.HandleFunc("/v2/email-service/webhook/1", func(w http.ResponseWriter, r *http.Request) {
suite.Equal(http.MethodPut, r.Method)
fmt.Fprintf(w, `{
"success": true,
"data": [
true
]
}`)
})
err := suite.client.Emails.Webhooks.UpdateWebhook(context.Background(), 1, "https://sendpulse.com")
suite.NoError(err)
}
func (suite *SendpulseTestSuite) TestEmailsService_WebhooksService_Delete() {
suite.mux.HandleFunc("/v2/email-service/webhook/1", func(w http.ResponseWriter, r *http.Request) {
suite.Equal(http.MethodDelete, r.Method)
fmt.Fprintf(w, `{
"success": true,
"data": [
true
]
}`)
})
err := suite.client.Emails.Webhooks.DeleteWebhook(context.Background(), 1)
suite.NoError(err)
}