-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_http_batch_check_test.go
122 lines (114 loc) · 2.6 KB
/
client_http_batch_check_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
119
120
121
122
package kickbox_test
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/wakumaku/kickbox"
"github.com/stretchr/testify/assert"
)
func TestClientHTTPBatchCheck(t *testing.T) {
tests := map[string]struct {
input string
expected *kickbox.VerifyBatchCheckResponse
}{
"starting": {
input: `{
"id": 123,
"status": "starting",
"success": true,
"message": null
}`,
expected: &kickbox.VerifyBatchCheckResponse{
ID: 123,
Status: "starting",
Success: true,
},
},
"processing": {
input: `{
"id": 123,
"status":"processing",
"progress":{
"deliverable": 1,
"undeliverable": 0,
"risky": 0,
"unknown": 0,
"total": 3,
"unprocessed": 2
},
"success": true,
"message": null
}`,
expected: &kickbox.VerifyBatchCheckResponse{
ID: 123,
Status: "processing",
Success: true,
},
},
"completed": {
input: `{
"id": 123,
"name": "Batch API Process - 05-12-2018-01-58-08",
"download_url": "https://{{DOWNLOAD_URL_HERE}}",
"created_at": "2018-05-12T18:58:08.000Z",
"status": "completed",
"stats": {
"deliverable": 2,
"undeliverable": 1,
"risky": 0,
"unknown": 0,
"sendex": 0.35,
"addresses": 3
},
"error": null,
"duration": 0,
"success": true,
"message": null
}`,
expected: &kickbox.VerifyBatchCheckResponse{
ID: 123,
Status: "completed",
Success: true,
},
},
"failed": {
input: `{
"id": 123,
"name": "Batch API Process - 05-12-2018-01-58-08",
"created_at": "2018-05-12T18:58:08.000Z",
"status": "failed",
"error": "Description of error here...",
"duration": 42,
"success": true,
"message": null
}`,
expected: &kickbox.VerifyBatchCheckResponse{
ID: 123,
Status: "failed",
Success: true,
},
},
}
handler := func(rw http.ResponseWriter, r *http.Request) {
jobID := strings.TrimPrefix(r.URL.Path, "/v2/verify-batch/")
test, found := tests[jobID]
if !found {
rw.WriteHeader(http.StatusInternalServerError)
return
}
rw.WriteHeader(http.StatusOK)
_, _ = rw.Write([]byte(test.input))
}
svr := httptest.NewServer(http.HandlerFunc(handler))
defer svr.Close()
client, err := kickbox.New("apikey", kickbox.OverrideBaseURL(svr.URL))
assert.Nil(t, err, "unexpected error")
for name, values := range tests {
resp, err := client.VerifyBatchCheck(context.TODO(), name)
assert.Nil(t, err)
assert.Equal(t, resp.ID, values.expected.ID)
assert.Equal(t, resp.Status, values.expected.Status)
}
}