forked from keighl/postmark
-
Notifications
You must be signed in to change notification settings - Fork 1
/
messages_outbound_test.go
247 lines (220 loc) · 6.95 KB
/
messages_outbound_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package postmark
import (
"fmt"
"net/http"
"testing"
"goji.io/pat"
)
func TestGetOutboundMessage(t *testing.T) {
responseJSON := `{
"TextBody": "Thank you for your order...",
"HtmlBody": "<p>Thank you for your order...</p>",
"Body": "SMTP dump data",
"Tag": "product-orders",
"MessageID": "07311c54-0687-4ab9-b034-b54b5bad88ba",
"To": [
{
"Email": "[email protected]",
"Name": null
}
],
"Cc": [],
"Bcc": [],
"Recipients": [
],
"ReceivedAt": "2014-02-14T11:12:54.8054242-05:00",
"From": "\"Joe\" <[email protected]>",
"Subject": "Parts Order #5454",
"Attachments": ["test-file.txt"],
"Status": "Sent",
"MessageEvents": [
{
"Recipient": "[email protected]",
"Type": "Delivered",
"ReceivedAt": "2014-02-14T11:13:10.8054242-05:00",
"Details": {
"DeliveryMessage": "smtp;250 2.0.0 OK l10si21599969igu.63 - gsmtp",
"DestinationServer": "yahoo-smtp-in.l.yahoo.com (433.899.888.26)",
"DestinationIP": "173.194.74.256"
}
},
{
"Recipient": "[email protected]",
"Type": "Opened",
"ReceivedAt": "2014-02-14T11:20:10.8054242-05:00",
"Details": {
"Summary": "Email opened with Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)"
}
},
{
"Recipient": "[email protected]",
"Type": "Bounced",
"ReceivedAt": "2014-02-14T11:20:15.8054242-05:00",
"Details": {
"Summary": "smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces.",
"BounceID": "374814878"
}
}
]
}`
tMux.HandleFunc(pat.Get("/messages/outbound/07311c54-0687-4ab9-b034-b54b5bad88ba/details"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})
res, err := client.GetOutboundMessage("07311c54-0687-4ab9-b034-b54b5bad88ba")
if err != nil {
t.Fatalf("GetOutboundMessage: %s", err.Error())
}
if res.MessageID != "07311c54-0687-4ab9-b034-b54b5bad88ba" {
t.Fatalf("GetOutboundMessage: wrong MessageID (%v)", res.MessageID)
}
}
func TestGetOutboundMessageDump(t *testing.T) {
dump := `From: \"John Doe\" <[email protected]> \r\nTo: \"[email protected]\" <[email protected]>\r\nReply-To: [email protected]\r\nDate: Fri, 14 Feb 2014 11:12:56 -0500\r\nSubject: Parts Order #5454\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: quoted-printable\r\nX-Mailer: aspNetEmail ver 4.0.0.22\r\nX-Job: 44013_34141\r\nX-virtual-MTA: shared1\r\nX-Complaints-To: [email protected]\r\nX-PM-RCPT: |bTB8NDQwMTN8MzQxNDF8anBAd2lsZGJpdC5jb20=|\r\nX-PM-Tag: product-orders\r\nX-PM-Message-Id: 07311c54-0687-4ab9-b034-b54b5bad88ba\r\nMessage-ID: <SC-ORD-MAIL4390fbe08b95f4257984dcaed896b4730@SC-ORD-MAIL4>\r\n\r\nThank you for your order=2E=2E=2E\r\n`
responseJSON := fmt.Sprintf(`{"Body": "%s"}`, dump)
tMux.HandleFunc(pat.Get("/messages/outbound/07311c54-0687-4ab9-b034-b54b5bad88ba/dump"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})
_, err := client.GetOutboundMessageDump("07311c54-0687-4ab9-b034-b54b5bad88ba")
if err != nil {
t.Fatalf("GetOutboundMessageDump: %s", err.Error())
}
}
func TestGetOutboundMessages(t *testing.T) {
responseJSON := `{
"TotalCount": 194,
"Messages": [
{
"Tag": "Invitation",
"MessageID": "0ac29aee-e1cd-480d-b08d-4f48548ff48d",
"To": [
{
"Email": "[email protected]",
"Name": null
}
],
"Cc": [],
"Bcc": [],
"Recipients": [
],
"ReceivedAt": "2014-02-20T07:25:02.8782715-05:00",
"From": "\"Joe\" <[email protected]>",
"Subject": "staging",
"Attachments": [],
"Status": "Sent"
}
]
}`
tMux.HandleFunc(pat.Get("/messages/outbound"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})
_, total, err := client.GetOutboundMessages(100, 0, map[string]interface{}{
"recipient": "[email protected]",
"tag": "welcome",
"status": "",
"todate": "2015-01-12",
"fromdate": "2015-01-01",
})
if err != nil {
t.Fatalf("GetOutboundMessages: %s", err.Error())
}
if total != 194 {
t.Fatalf("GetOutboundMessages: wrong total (%d)", total)
}
}
func TestGetOutboundMessagesOpens(t *testing.T) {
responseJSON := `{
"TotalCount": 1,
"Opens": [
{
"FirstOpen": true,
"Client": {
"Name": "Chrome 34.0.1847.131",
"Company": "Google Inc.",
"Family": "Chrome"
},
"OS": {
"Name": "OS X 10.7 Lion",
"Company": "Apple Computer, Inc.",
"Family": "OS X"
},
"Platform": "WebMail",
"UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36",
"ReadSeconds": 16,
"Geo": {
"CountryISOCode": "RS",
"Country": "Serbia",
"RegionISOCode": "VO",
"Region": "Autonomna Pokrajina Vojvodina",
"City": "Novi Sad",
"Zip": "21000",
"Coords": "45.2517,19.8369",
"IP": "188.2.95.4"
},
"MessageID": "927e56d4-dc66-4070-bbf0-1db76c2ae14b",
"ReceivedAt": "2014-04-30T05:04:23.8768746-04:00",
"Tag": "welcome-user",
"Recipient": "[email protected]"
}
]
}`
tMux.HandleFunc(pat.Get("/messages/outbound/opens"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})
_, total, err := client.GetOutboundMessagesOpens(100, 0, map[string]interface{}{
"recipient": "[email protected]",
})
if err != nil {
t.Fatalf("GetOutboundMessagesOpens: %s", err.Error())
}
if total != 1 {
t.Fatalf("GetOutboundMessagesOpens: wrong total (%d)", total)
}
}
func TestGetOutboundMessageOpens(t *testing.T) {
responseJSON := `{
"TotalCount": 1,
"Opens": [
{
"Client": {
"Name": "Chrome 34.0.1847.131",
"Company": "Google Inc.",
"Family": "Chrome"
},
"OS": {
"Name": "OS X 10.7 Lion",
"Company": "Apple Computer, Inc.",
"Family": "OS X"
},
"Platform": "WebMail",
"UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36",
"ReadSeconds": 16,
"Geo": {
"CountryISOCode": "RS",
"Country": "Serbia",
"RegionISOCode": "VO",
"Region": "Autonomna Pokrajina Vojvodina",
"City": "Novi Sad",
"Zip": "21000",
"Coords": "45.2517,19.8369",
"IP": "188.2.95.4"
},
"MessageID": "927e56d4-dc66-4070-bbf0-1db76c2ae14b",
"ReceivedAt": "2014-04-30T05:04:23.8768746-04:00",
"Tag": "welcome-user",
"Recipient": "[email protected]"
}
]
}`
tMux.HandleFunc(pat.Get("/messages/outbound/opens/927e56d4-dc66-4070-bbf0-1db76c2ae14b"), func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(responseJSON))
})
_, total, err := client.GetOutboundMessageOpens("927e56d4-dc66-4070-bbf0-1db76c2ae14b", 100, 0)
if err != nil {
t.Fatalf("GetOutboundMessageOpens: %s", err.Error())
}
if total != 1 {
t.Fatalf("GetOutboundMessageOpens: wrong total (%d)", total)
}
}