@@ -8,45 +8,47 @@ import (
8
8
)
9
9
10
10
func TestGetDeliveryStats (t * testing.T ) {
11
+ responseJSON := `{
12
+ "InactiveMails": 192,
13
+ "Bounces": [
14
+ {
15
+ "Name": "All",
16
+ "Count": 253
17
+ },
18
+ {
19
+ "Type": "HardBounce",
20
+ "Name": "Hard bounce",
21
+ "Count": 195
22
+ },
23
+ {
24
+ "Type": "Transient",
25
+ "Name": "Message delayed",
26
+ "Count": 10
27
+ },
28
+ {
29
+ "Type": "AutoResponder",
30
+ "Name": "Auto responder",
31
+ "Count": 14
32
+ },
33
+ {
34
+ "Type": "SpamNotification",
35
+ "Name": "Spam notification",
36
+ "Count": 3
37
+ },
38
+ {
39
+ "Type": "SoftBounce",
40
+ "Name": "Soft bounce",
41
+ "Count": 30
42
+ },
43
+ {
44
+ "Type": "SpamComplaint",
45
+ "Name": "Spam complaint",
46
+ "Count": 1
47
+ }
48
+ ]}`
49
+
11
50
tMux .HandleFunc (pat .Get ("/deliverystats" ), func (w http.ResponseWriter , req * http.Request ) {
12
- w .Write ([]byte (`{
13
- "InactiveMails": 192,
14
- "Bounces": [
15
- {
16
- "Name": "All",
17
- "Count": 253
18
- },
19
- {
20
- "Type": "HardBounce",
21
- "Name": "Hard bounce",
22
- "Count": 195
23
- },
24
- {
25
- "Type": "Transient",
26
- "Name": "Message delayed",
27
- "Count": 10
28
- },
29
- {
30
- "Type": "AutoResponder",
31
- "Name": "Auto responder",
32
- "Count": 14
33
- },
34
- {
35
- "Type": "SpamNotification",
36
- "Name": "Spam notification",
37
- "Count": 3
38
- },
39
- {
40
- "Type": "SoftBounce",
41
- "Name": "Soft bounce",
42
- "Count": 30
43
- },
44
- {
45
- "Type": "SpamComplaint",
46
- "Name": "Spam complaint",
47
- "Count": 1
48
- }
49
- ]}` ))
51
+ w .Write ([]byte (responseJSON ))
50
52
})
51
53
52
54
res , err := client .GetDeliveryStats ()
@@ -60,44 +62,46 @@ func TestGetDeliveryStats(t *testing.T) {
60
62
}
61
63
62
64
func TestGetBounces (t * testing.T ) {
63
- tMux .HandleFunc (pat .Get ("/bounces" ), func (w http.ResponseWriter , req * http.Request ) {
64
- w .Write ([]byte (`{
65
- "TotalCount": 253,
66
- "Bounces": [
67
- {
68
- "ID": 692560173,
69
- "Type": "HardBounce",
70
- "TypeCode": 1,
71
- "Name": "Hard bounce",
72
- "Tag": "Invitation",
73
- "MessageID": "2c1b63fe-43f2-4db5-91b0-8bdfa44a9316",
74
- "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
75
- "Details": "action: failed\r\n",
76
-
77
- "BouncedAt": "2014-01-15T16:09:19.6421112-05:00",
78
- "DumpAvailable": false,
79
- "Inactive": false,
80
- "CanActivate": true,
81
- "Subject": "SC API5 Test"
82
- },
83
- {
84
- "ID": 676862817,
85
- "Type": "HardBounce",
86
- "TypeCode": 1,
87
- "Name": "Hard bounce",
88
- "Tag": "Invitation",
89
- "MessageID": "623b2e90-82d0-4050-ae9e-2c3a734ba091",
90
- "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
91
- "Details": "smtp;554 delivery error: dd This user doesn't have a yahoo.com account ([email protected] ) [0] - mta1543.mail.ne1.yahoo.com",
92
-
93
- "BouncedAt": "2013-10-18T09:49:59.8253577-04:00",
94
- "DumpAvailable": false,
95
- "Inactive": true,
96
- "CanActivate": true,
97
- "Subject": "Production API Test"
98
- }
65
+ responseJSON := `{
66
+ "TotalCount": 253,
67
+ "Bounces": [
68
+ {
69
+ "ID": 692560173,
70
+ "Type": "HardBounce",
71
+ "TypeCode": 1,
72
+ "Name": "Hard bounce",
73
+ "Tag": "Invitation",
74
+ "MessageID": "2c1b63fe-43f2-4db5-91b0-8bdfa44a9316",
75
+ "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
76
+ "Details": "action: failed\r\n",
77
+
78
+ "BouncedAt": "2014-01-15T16:09:19.6421112-05:00",
79
+ "DumpAvailable": false,
80
+ "Inactive": false,
81
+ "CanActivate": true,
82
+ "Subject": "SC API5 Test"
83
+ },
84
+ {
85
+ "ID": 676862817,
86
+ "Type": "HardBounce",
87
+ "TypeCode": 1,
88
+ "Name": "Hard bounce",
89
+ "Tag": "Invitation",
90
+ "MessageID": "623b2e90-82d0-4050-ae9e-2c3a734ba091",
91
+ "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
92
+ "Details": "smtp;554 delivery error: dd This user doesn't have a yahoo.com account ([email protected] ) [0] - mta1543.mail.ne1.yahoo.com",
93
+
94
+ "BouncedAt": "2013-10-18T09:49:59.8253577-04:00",
95
+ "DumpAvailable": false,
96
+ "Inactive": true,
97
+ "CanActivate": true,
98
+ "Subject": "Production API Test"
99
+ }
99
100
]
100
- }` ))
101
+ }`
102
+
103
+ tMux .HandleFunc (pat .Get ("/bounces" ), func (w http.ResponseWriter , req * http.Request ) {
104
+ w .Write ([]byte (responseJSON ))
101
105
})
102
106
103
107
_ , total , err := client .GetBounces (100 , 0 , map [string ]interface {}{
@@ -114,24 +118,26 @@ func TestGetBounces(t *testing.T) {
114
118
}
115
119
116
120
func TestGetBounce (t * testing.T ) {
121
+ responseJSON := `{
122
+ "ID": 692560173,
123
+ "Type": "HardBounce",
124
+ "TypeCode": 1,
125
+ "Name": "Hard bounce",
126
+ "Tag": "Invitation",
127
+ "MessageID": "2c1b63fe-43f2-4db5-91b0-8bdfa44a9316",
128
+ "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
129
+ "Details": "action: failed\r\n",
130
+
131
+ "BouncedAt": "2014-01-15T16:09:19.6421112-05:00",
132
+ "DumpAvailable": false,
133
+ "Inactive": false,
134
+ "CanActivate": true,
135
+ "Subject": "SC API5 Test",
136
+ "Content": "Return-Path: <>\r\nReceived: …"
137
+ }`
138
+
117
139
tMux .HandleFunc (pat .Get ("/bounces/692560173" ), func (w http.ResponseWriter , req * http.Request ) {
118
- w .Write ([]byte (`{
119
- "ID": 692560173,
120
- "Type": "HardBounce",
121
- "TypeCode": 1,
122
- "Name": "Hard bounce",
123
- "Tag": "Invitation",
124
- "MessageID": "2c1b63fe-43f2-4db5-91b0-8bdfa44a9316",
125
- "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
126
- "Details": "action: failed\r\n",
127
-
128
- "BouncedAt": "2014-01-15T16:09:19.6421112-05:00",
129
- "DumpAvailable": false,
130
- "Inactive": false,
131
- "CanActivate": true,
132
- "Subject": "SC API5 Test",
133
- "Content": "Return-Path: <>\r\nReceived: …"
134
- }` ))
140
+ w .Write ([]byte (responseJSON ))
135
141
})
136
142
137
143
res , err := client .GetBounce (692560173 )
@@ -146,10 +152,12 @@ func TestGetBounce(t *testing.T) {
146
152
}
147
153
148
154
func TestGetBounceDump (t * testing.T ) {
155
+ responseJSON := `{
156
+ "Body": "..."
157
+ }`
158
+
149
159
tMux .HandleFunc (pat .Get ("/bounces/692560173/dump" ), func (w http.ResponseWriter , req * http.Request ) {
150
- w .Write ([]byte (`{
151
- "Body": "..."
152
- }` ))
160
+ w .Write ([]byte (responseJSON ))
153
161
})
154
162
155
163
res , err := client .GetBounceDump (692560173 )
@@ -164,27 +172,29 @@ func TestGetBounceDump(t *testing.T) {
164
172
}
165
173
166
174
func TestActivateBounce (t * testing.T ) {
175
+ responseJSON := `{
176
+ "Message": "OK",
177
+ "Bounce": {
178
+ "ID": 692560173,
179
+ "Type": "HardBounce",
180
+ "TypeCode": 1,
181
+ "Name": "Hard bounce",
182
+ "Tag": "Invitation",
183
+ "MessageID": "2c1b63fe-43f2-4db5-91b0-8bdfa44a9316",
184
+ "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
185
+ "Details": "action: failed\r\n",
186
+
187
+ "BouncedAt": "2014-01-15T16:09:19.6421112-05:00",
188
+ "DumpAvailable": false,
189
+ "Inactive": false,
190
+ "CanActivate": true,
191
+ "Subject": "SC API5 Test",
192
+ "Content": "Return-Path: <>\r\nReceived: …"
193
+ }
194
+ }`
195
+
167
196
tMux .HandleFunc (pat .Put ("/bounces/692560173/activate" ), func (w http.ResponseWriter , req * http.Request ) {
168
- w .Write ([]byte (`{
169
- "Message": "OK",
170
- "Bounce": {
171
- "ID": 692560173,
172
- "Type": "HardBounce",
173
- "TypeCode": 1,
174
- "Name": "Hard bounce",
175
- "Tag": "Invitation",
176
- "MessageID": "2c1b63fe-43f2-4db5-91b0-8bdfa44a9316",
177
- "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
178
- "Details": "action: failed\r\n",
179
-
180
- "BouncedAt": "2014-01-15T16:09:19.6421112-05:00",
181
- "DumpAvailable": false,
182
- "Inactive": false,
183
- "CanActivate": true,
184
- "Subject": "SC API5 Test",
185
- "Content": "Return-Path: <>\r\nReceived: …"
186
- }
187
- }` ))
197
+ w .Write ([]byte (responseJSON ))
188
198
})
189
199
190
200
res , mess , err := client .ActivateBounce (692560173 )
@@ -202,12 +212,14 @@ func TestActivateBounce(t *testing.T) {
202
212
}
203
213
204
214
func TestGetBouncedTags (t * testing.T ) {
215
+ responseJSON := `[
216
+ "tag1",
217
+ "tag2",
218
+ "tag3"]
219
+ `
220
+
205
221
tMux .HandleFunc (pat .Get ("/bounces/tags" ), func (w http.ResponseWriter , req * http.Request ) {
206
- w .Write ([]byte (`[
207
- "tag1",
208
- "tag2",
209
- "tag3"]
210
- ` ))
222
+ w .Write ([]byte (responseJSON ))
211
223
})
212
224
213
225
res , err := client .GetBouncedTags ()
0 commit comments