Skip to content

Commit 109b99c

Browse files
author
Kyle Truscott
committed
* Bypass inbound rules
* Rejigger how test data gets tossed around
1 parent c986a0e commit 109b99c

File tree

7 files changed

+572
-481
lines changed

7 files changed

+572
-481
lines changed

bounce_test.go

Lines changed: 132 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,47 @@ import (
88
)
99

1010
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+
1150
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))
5052
})
5153

5254
res, err := client.GetDeliveryStats()
@@ -60,44 +62,46 @@ func TestGetDeliveryStats(t *testing.T) {
6062
}
6163

6264
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-
"Email": "[email protected]",
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-
"Email": "[email protected]",
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+
"Email": "[email protected]",
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+
"Email": "[email protected]",
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+
}
99100
]
100-
}`))
101+
}`
102+
103+
tMux.HandleFunc(pat.Get("/bounces"), func(w http.ResponseWriter, req *http.Request) {
104+
w.Write([]byte(responseJSON))
101105
})
102106

103107
_, total, err := client.GetBounces(100, 0, map[string]interface{}{
@@ -114,24 +118,26 @@ func TestGetBounces(t *testing.T) {
114118
}
115119

116120
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+
"Email": "[email protected]",
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+
117139
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-
"Email": "[email protected]",
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))
135141
})
136142

137143
res, err := client.GetBounce(692560173)
@@ -146,10 +152,12 @@ func TestGetBounce(t *testing.T) {
146152
}
147153

148154
func TestGetBounceDump(t *testing.T) {
155+
responseJSON := `{
156+
"Body": "..."
157+
}`
158+
149159
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))
153161
})
154162

155163
res, err := client.GetBounceDump(692560173)
@@ -164,27 +172,29 @@ func TestGetBounceDump(t *testing.T) {
164172
}
165173

166174
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+
"Email": "[email protected]",
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+
167196
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-
"Email": "[email protected]",
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))
188198
})
189199

190200
res, mess, err := client.ActivateBounce(692560173)
@@ -202,12 +212,14 @@ func TestActivateBounce(t *testing.T) {
202212
}
203213

204214
func TestGetBouncedTags(t *testing.T) {
215+
responseJSON := `[
216+
"tag1",
217+
"tag2",
218+
"tag3"]
219+
`
220+
205221
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))
211223
})
212224

213225
res, err := client.GetBouncedTags()

email_test.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ var testEmail = Email{
3939
}
4040

4141
func TestSendEmail(t *testing.T) {
42+
responseJSON := `{
43+
44+
"SubmittedAt": "2014-02-17T07:25:01.4178645-05:00",
45+
"MessageID": "0a129aee-e1cd-480d-b08d-4f48548ff48d",
46+
"ErrorCode": 0,
47+
"Message": "OK"
48+
}`
49+
4250
tMux.HandleFunc(pat.Post("/email"), func(w http.ResponseWriter, req *http.Request) {
43-
w.Write([]byte(`{
44-
45-
"SubmittedAt": "2014-02-17T07:25:01.4178645-05:00",
46-
"MessageID": "0a129aee-e1cd-480d-b08d-4f48548ff48d",
47-
"ErrorCode": 0,
48-
"Message": "OK"
49-
}`))
51+
w.Write([]byte(responseJSON))
5052
})
5153

5254
res, err := client.SendEmail(testEmail)
@@ -61,23 +63,25 @@ func TestSendEmail(t *testing.T) {
6163
}
6264

6365
func TestSendEmailBatch(t *testing.T) {
66+
responseJSON := `[
67+
{
68+
"ErrorCode": 0,
69+
"Message": "OK",
70+
"MessageID": "b7bc2f4a-e38e-4336-af7d-e6c392c2f817",
71+
"SubmittedAt": "2010-11-26T12:01:05.1794748-05:00",
72+
73+
},
74+
{
75+
"ErrorCode": 0,
76+
"Message": "OK",
77+
"MessageID": "e2ecbbfc-fe12-463d-b933-9fe22915106d",
78+
"SubmittedAt": "2010-11-26T12:01:05.1794748-05:00",
79+
80+
}
81+
]`
82+
6483
tMux.HandleFunc(pat.Post("/email/batch"), func(w http.ResponseWriter, req *http.Request) {
65-
w.Write([]byte(`[
66-
{
67-
"ErrorCode": 0,
68-
"Message": "OK",
69-
"MessageID": "b7bc2f4a-e38e-4336-af7d-e6c392c2f817",
70-
"SubmittedAt": "2010-11-26T12:01:05.1794748-05:00",
71-
72-
},
73-
{
74-
"ErrorCode": 0,
75-
"Message": "OK",
76-
"MessageID": "e2ecbbfc-fe12-463d-b933-9fe22915106d",
77-
"SubmittedAt": "2010-11-26T12:01:05.1794748-05:00",
78-
79-
}
80-
]`))
84+
w.Write([]byte(responseJSON))
8185
})
8286

8387
res, err := client.SendEmailBatch([]Email{testEmail, testEmail})

messages_inbound.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,22 @@ func (client *Client) GetInboundMessages(count int64, offset int64, options map[
9494
err := client.doRequest("GET", path, nil, &res)
9595
return res.Messages, res.TotalCount, err
9696
}
97+
98+
///////////////////////////////////////
99+
///////////////////////////////////////
100+
101+
// BypassInboundMessage - Bypass rules for a blocked inbound message
102+
func (client *Client) BypassInboundMessage(messageID string) error {
103+
errRes := APIError{}
104+
path := fmt.Sprintf("messages/inbound/%s/bypass", messageID)
105+
err := client.doRequest("PUT", path, nil, &errRes)
106+
if err != nil {
107+
return err
108+
}
109+
110+
if errRes.ErrorCode == 0 {
111+
return nil
112+
}
113+
114+
return errRes
115+
}

0 commit comments

Comments
 (0)