-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook_test.go
63 lines (52 loc) · 1.42 KB
/
webhook_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
package swervpay
import (
"context"
"encoding/json"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func TestTestWebhook(t *testing.T) {
setup()
defer teardown()
webhookId := "wbh_123456789"
mux.HandleFunc("/webhook/"+webhookId+"/test", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
ret := &DefaultResponse{
Message: "Test webhook sent successfully",
}
err := json.NewEncoder(w).Encode(&ret)
if err != nil {
panic(err)
}
})
resp, err := client.Webhook.Test(context.Background(), webhookId)
if err != nil {
t.Errorf("Err retrying webhook: %v", err)
}
assert.Equal(t, resp.Message, "Test webhook sent successfully")
}
func TestRetryWebhook(t *testing.T) {
setup()
defer teardown()
logId := "tri_123456789"
mux.HandleFunc("/webhook/"+logId+"/retry", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
ret := &DefaultResponse{
Message: "Retry webhook sent successfully",
}
err := json.NewEncoder(w).Encode(&ret)
if err != nil {
panic(err)
}
})
resp, err := client.Webhook.Retry(context.Background(), logId)
if err != nil {
t.Errorf("Err retrying webhook: %v", err)
}
assert.Equal(t, resp.Message, "Retry webhook sent successfully")
}