-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
115 lines (110 loc) · 3.04 KB
/
Copy pathclient_test.go
File metadata and controls
115 lines (110 loc) · 3.04 KB
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
package blackbox
import (
"context"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)
func defaultHandler(response string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(response))
}
}
func Test_SendSMS(t *testing.T) {
type test struct {
name string
handler http.HandlerFunc
req *SendSMSRequest
}
cases := []test{
{
name: "t1",
handler: defaultHandler(`
{
"response": {
"status": {
"code": "0000",
"type": "SUCCESS",
"description": "REQUEST_SUCCESSFUL",
"meta": "SMS_QUEUE"
},
"content": {
"description": "2 messages queued. 4 SMS deducted, 2504256 SMS available.",
"messages": {
"message": "2504256",
"request": {
"sms": [
{
"event": "OUTBOX",
"recipient": "+25472212356",
"message": "This is an unscheduled message",
"sender": "",
"keyword": "",
"reference": "",
"status": "FAILED",
"status_description": "INVALID_SERVICE",
"date": "2015-01-28 18:45:00"
},
{
"event": "OUTBOX",
"recipient": "+25472212356",
"message": "This is a shortcode message via music keyword",
"sender": "20717",
"keyword": "MUSIC",
"reference": "bb0b30ea2208c99b1164c965ade9dfb8cbb23fdaa1",
"status": "SENT",
"status_description": "OK",
"date": "2015-01-28 18:45:00"
},
{
"event": "OUTBOX",
"recipient": "+25472212356",
"message": "This is a shortcode message without keyword",
"sender": "20333",
"reference": "bb0b30ea2208c99b1164c965ade9dfb8cbb23fdaa2",
"status": "SENT",
"status_description": "OK",
"date": "2015-01-28 18:45:00"
},
{
"event": "OUTBOX",
"recipient": "+25473312356",
"message": "This is a scheduled message",
"sender": "SENDER_123",
"scheduled_date": "2015-01-28 18:45:00",
"reference": "bb0b30ea2208c99b1164c965ade9dfb8cbb23fdaa3",
"status": "SCHEDULED",
"status_description": "OK",
"date": "2015-01-28 18:45:00"
}
]
}
}
}
}
}`),
req: &SendSMSRequest{
Messages: []Message{
{
Recipient: "w1",
Message: "w2",
Sender: "h1",
Keyword: "h2",
},
},
},
},
}
for _, tc := range cases {
ts := httptest.NewServer(tc.handler)
c := NewClient(ts.URL, "", "", http.DefaultClient)
t.Run(tc.name, func(t *testing.T) {
resp, err := c.SendSMS(context.Background(), tc.req)
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, resp.Response.Content.Description, "2 messages queued. 4 SMS deducted, 2504256 SMS available.")
})
ts.Close()
}
}