-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhooks_test.go
164 lines (157 loc) · 4.14 KB
/
webhooks_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
package postmark
import (
"encoding/json"
"testing"
)
// from: http://developer.postmarkapp.com/developer-bounce-webhook.html
const bounceExample = `
{
"ID": 42,
"Type": "HardBounce",
"TypeCode": 1,
"Name": "Hard bounce",
"Tag": "Test",
"MessageID": "883953f4-6105-42a2-a16a-77a8eac79483",
"Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
"Details": "Test bounce details",
"Email": "[email protected]",
"BouncedAt": "2014-08-01T13:28:10.2735393-04:00",
"DumpAvailable": true,
"Inactive": true,
"CanActivate": true,
"Subject": "Test subject"
}
`
func TestBounceWebhookUnmarshal(t *testing.T) {
var v BounceWebhook
if err := json.Unmarshal([]byte(bounceExample), &v); err != nil {
t.Errorf("error unmarshalling json: %v", err)
}
}
// from: http://developer.postmarkapp.com/developer-inbound-webhook.html
const inboundExample = `
{
"FromName": "Postmarkapp Support",
"From": "[email protected]",
"FromFull": {
"Email": "[email protected]",
"Name": "Postmarkapp Support",
"MailboxHash": ""
},
"To": "\"Firstname Lastname\" <[email protected]>",
"ToFull": [
{
"Email": "[email protected]",
"Name": "Firstname Lastname",
"MailboxHash": "SampleHash"
}
],
"Cc": "\"First Cc\" <[email protected]>, [email protected]>",
"CcFull": [
{
"Email": "[email protected]",
"Name": "First Cc",
"MailboxHash": ""
},
{
"Email": "[email protected]",
"Name": "",
"MailboxHash": ""
}
],
"Bcc": "\"First Bcc\" <[email protected]>, [email protected]>",
"BccFull": [
{
"Email": "[email protected]",
"Name": "First Bcc",
"MailboxHash": ""
},
{
"Email": "[email protected]",
"Name": "",
"MailboxHash": ""
}
],
"OriginalRecipient": "[email protected]",
"Subject": "Test subject",
"MessageID": "73e6d360-66eb-11e1-8e72-a8904824019b",
"ReplyTo": "[email protected]",
"MailboxHash": "SampleHash",
"Date": "Fri, 1 Aug 2014 16:45:32 -04:00",
"TextBody": "This is a test text body.",
"HtmlBody": "<html><body><p>This is a test html body.<\/p><\/body><\/html>",
"StrippedTextReply": "This is the reply text",
"Tag": "TestTag",
"Headers": [
{
"Name": "X-Header-Test",
"Value": ""
},
{
"Name": "X-Spam-Status",
"Value": "No"
},
{
"Name": "X-Spam-Score",
"Value": "-0.1"
},
{
"Name": "X-Spam-Tests",
"Value": "DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_PASS"
}
],
"Attachments": [
{
"Name": "test.txt",
"Content": "VGhpcyBpcyBhdHRhY2htZW50IGNvbnRlbnRzLCBiYXNlLTY0IGVuY29kZWQu",
"ContentType": "text/plain",
"ContentLength": 45
}
]
}
`
func TestInboundWebhookUnmarshal(t *testing.T) {
var v InboundWebhook
if err := json.Unmarshal([]byte(inboundExample), &v); err != nil {
t.Errorf("error unmarshalling json: %v", err)
}
}
// from: http://developer.postmarkapp.com/developer-open-webhook.html
const openExample = `
{
"FirstOpen": true,
"Client": {
"Name": "Chrome 35.0.1916.153",
"Company": "Google",
"Family": "Chrome"
},
"OS": {
"Name": "OS X 10.7 Lion",
"Company": "Apple Computer, Inc.",
"Family": "OS X 10"
},
"Platform": "WebMail",
"UserAgent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/35.0.1916.153 Safari\/537.36",
"ReadSeconds": 5,
"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": "883953f4-6105-42a2-a16a-77a8eac79483",
"ReceivedAt": "2014-06-01T12:00:00",
"Tag": "welcome-email",
"Recipient": "[email protected]"
}
`
func TestOpenWebhookUnmarshal(t *testing.T) {
var v OpenWebhook
if err := json.Unmarshal([]byte(openExample), &v); err != nil {
t.Errorf("error unmarshalling json: %v", err)
}
}