This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook_test.go
118 lines (96 loc) · 2.97 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
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
111
112
113
114
115
116
117
118
package bitindex
import "testing"
// TestClient_GetWebhookConfig tests the GetWebhookConfig()
func TestClient_GetWebhookConfig(t *testing.T) {
// Skip this test in short mode (not needed)
if testing.Short() {
t.Skip("skipping testing in short mode")
}
// Create a new client object to handle your queries (supply an API Key)
client, err := NewClient(testAPIKey, NetworkMain, nil)
if err != nil {
t.Fatal(err)
}
var resp *WebhookConfigResponse
resp, err = client.GetWebhookConfig()
if err != nil {
t.Fatal("error occurred: " + err.Error())
}
if len(resp.URL) == 0 {
t.Fatal("we should have the url", resp.URL)
}
}
// TestClient_GetMonitoredAddresses tests the GetMonitoredAddresses()
func TestClient_GetMonitoredAddresses(t *testing.T) {
// Skip this test in short mode (not needed)
if testing.Short() {
t.Skip("skipping testing in short mode")
}
// Create a new client object to handle your queries (supply an API Key)
client, err := NewClient(testAPIKey, NetworkMain, nil)
if err != nil {
t.Fatal(err)
}
var resp MonitoredAddresses
resp, err = client.GetMonitoredAddresses()
if err != nil {
t.Fatal("error occurred: " + err.Error())
}
if len(resp) == 0 {
t.Fatal("should have monitored addresses", resp)
}
}
// TestClient_UpdateWebhookConfig tests the UpdateWebhookConfig()
func TestClient_UpdateWebhookConfig(t *testing.T) {
// Skip this test in short mode (not needed)
if testing.Short() {
t.Skip("skipping testing in short mode")
}
// Create a new client object to handle your queries (supply an API Key)
client, err := NewClient(testAPIKey, NetworkMain, nil)
if err != nil {
t.Fatal(err)
}
var config *WebhookConfigResponse
req := new(WebhookUpdateConfig)
req.Secret = "Top-Secret-New-Key2"
req.Enabled = false
// req.URL = "http://example-update-me-to-your.com/path/callback2"
config, err = client.UpdateWebhookConfig(req)
if err != nil {
t.Fatal("error occurred: " + err.Error())
}
if len(config.ID) == 0 {
t.Fatal("we should at least have an id", config.ID)
}
if config.Secret != req.Secret {
t.Fatal("secret should have updated", req.Secret, config.Secret)
}
}
// TestClient_AddMonitoredAddresses tests the AddMonitoredAddresses()
func TestClient_AddMonitoredAddresses(t *testing.T) {
// Skip this test in short mode (not needed)
if testing.Short() {
t.Skip("skipping testing in short mode")
}
// Create a new client object to handle your queries (supply an API Key)
client, err := NewClient(testAPIKey, NetworkMain, nil)
if err != nil {
t.Fatal(err)
}
var req MonitoredAddresses
var add MonitoredAddress
add.Address = "1M6N389jhRi5DQgoQcNir2e2REpYeAYavD"
req = append(req, add)
var resp MonitoredAddresses
resp, err = client.AddMonitoredAddresses(&req)
if err != nil {
t.Fatal("error occurred: " + err.Error())
}
if len(resp) == 0 {
t.Fatal("should have monitored addresses", resp)
}
if resp[0].Address != add.Address {
t.Fatal("address returned should be the one we added", resp[0].Address, add.Address)
}
}