-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
114 lines (101 loc) · 2.26 KB
/
api_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
package mitake
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestClient_SendBatch(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/SmSendPost.asp", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testINI(t, r, `[0]
dstaddr=0987654321
smbody=Test 1
[1]
dstaddr=0987654322
smbody=Test 2`)
fmt.Fprint(w, `[0]
msgid=1010079522
statuscode=1
[1]
msgid=1010079523
statuscode=4
AccountPoint=98`)
})
messages := []Message{
{
Dstaddr: "0987654321",
Smbody: "Test 1",
},
{
Dstaddr: "0987654322",
Smbody: "Test 2",
},
}
resp, err := client.SendBatch(messages)
if err != nil {
t.Errorf("SendBatch returned unexpected error: %v", err)
}
want := []*MessageResult{
{
Msgid: "1010079522",
Statuscode: StatusCode("1"),
},
{
Msgid: "1010079523",
Statuscode: StatusCode("4"),
},
}
if !reflect.DeepEqual(resp.Results, want) {
t.Errorf("SendBatch returned %+v, want %+v", resp.Results, want)
}
}
func TestClient_QueryAccountPoint(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/SmQueryGet.asp", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `AccountPoint=100`)
})
ap, err := client.QueryAccountPoint()
if err != nil {
t.Errorf("QueryAccountPoint returned unexpected error: %v", err)
}
if ap != 100 {
t.Errorf("QueryAccountPoint returned %+v, want %+v", ap, 100)
}
}
func TestClient_QueryMessageStatus(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/SmQueryGet.asp", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `1010079522 1 20170101010010
1010079523 4 20170101010011`)
})
resp, err := client.QueryMessageStatus([]string{"1010079522", "1010079523"})
if err != nil {
t.Errorf("QueryMessageStatus returned unexpected error: %v", err)
}
want := []*MessageStatus{
{
MessageResult: MessageResult{
Msgid: "1010079522",
Statuscode: StatusCode("1"),
},
StatusTime: "20170101010010",
},
{
MessageResult: MessageResult{
Msgid: "1010079523",
Statuscode: StatusCode("4"),
},
StatusTime: "20170101010011",
},
}
if !reflect.DeepEqual(resp.Statuses, want) {
t.Errorf("QueryMessageStatus returned %+v, want %+v", resp.Statuses, want)
}
}