-
Notifications
You must be signed in to change notification settings - Fork 30k
/
mailgun-js-tests.ts
150 lines (129 loc) · 4.45 KB
/
mailgun-js-tests.ts
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
import * as mailgunFactory from 'mailgun-js';
import mailgunFactory2 = require('mailgun-js');
import * as FormData from 'form-data';
const mailgun = new mailgunFactory({
apiKey: 'auth.api_key',
domain: 'auth.domain',
});
const mailgun2 = new mailgunFactory2({
apiKey: 'auth.api_key',
domain: 'auth.domain',
});
const logger = (httpOptions: mailgunFactory.LoggerHttpOptions, payload: string, form: FormData) => {};
const mailgun3 = new mailgunFactory2({
apiKey: 'auth.api_key',
domain: 'auth.domain',
testMode: true,
testModeLogger: logger,
});
mailgun.messages().send(
{
to: 'fixture.message.to',
},
err => {
console.log;
},
);
const exampleSendData: mailgunFactory.messages.SendData = {
to: 'someone@email.com',
attachment: new mailgun.Attachment({
data: 'filepath',
filename: 'my_custom_name.png',
}),
inline: [
new mailgun.Attachment({
data: 'filepath',
filename: 'my_custom_name_2.png',
}),
'my_custom_file_3.png',
Buffer.from('plain text'),
],
};
mailgun.messages().send(exampleSendData, (err, body) => {});
const arraySendData: mailgunFactory.messages.SendData = {
to: ['someone@email.com', 'else@email.com'],
cc: ['cc1@email.com', 'cc2@email.com'],
bcc: ['bcc1@email.com', 'bcc2@email.com'],
attachment: [
new mailgun.Attachment({
data: 'filepath',
filename: 'my_custom_name.png',
}),
],
'o:tag': ['cats', 'rainbows'],
};
mailgun.messages().send(arraySendData, (err, body) => {});
const exampleSendDataWithTemplate: mailgunFactory.messages.SendTemplateData = {
to: 'someone@email.com',
template: 'my-template',
'v:template-variable': 'foo',
};
const exampleSendDataWithTemplate2: mailgunFactory.messages.SendTemplateData = {
to: 'someone@email.com',
template: 'my-template',
'v:number': 123,
'v:boolean': true,
'v:string': '',
'v:undefined': undefined,
'v:complexObject': {
whatever: 123,
test: true,
},
};
const exampleBatchDataWithRecipientVariables1: mailgunFactory.messages.BatchData = {
to: 'someone@email.com',
subject: 'Hello, %recipient.name%',
text: 'You have %recipient.invitations% new invitations',
'recipient-variables': {
'alice@example.com': {
name: 'Alice',
invitations: 3
},
'bob@example.com': {
name: 'Bob',
invitations: 2
},
}
};
const exampleBatchDataWithRecipientVariables2: mailgunFactory.messages.BatchData = {
to: 'someone@email.com',
subject: 'Hello, %recipient.name%',
text: 'You have %recipient.invitations% new invitations',
'recipient-variables': JSON.stringify({
'alice@example.com': {
name: 'Alice',
invitations: 3
},
})
};
const exampleSendDataTemplateResponse: Promise<mailgunFactory.messages.SendResponse> = mailgun
.messages()
.send(exampleSendDataWithTemplate);
let validationResultPromise: Promise<mailgunFactory.validation.ValidateResponse>;
validationResultPromise = mailgun.validate('foo@mailgun.net');
validationResultPromise = mailgun.validate('foo@mailgun.net', true);
validationResultPromise = mailgun.validate('foo@mailgun.net', true, { mailbox_verification: true });
validationResultPromise = mailgun.validate('foo@mailgun.net', { mailbox_verification: false, api_key: '...' });
mailgun.validate('foo@mailgun.net', (error, body) => {});
mailgun.validate('foo@mailgun.net', true, (error, body) => {});
mailgun.validate('foo@mailgun.net', true, { mailbox_verification: true }, (error, body) => {});
mailgun.validate('foo@mailgun.net', { mailbox_verification: false, api_key: '...' }, (error, body) => {});
const validationResult6: mailgunFactory.validation.ValidateResponse = {
address: 'foo@mailgun.net',
did_you_mean: 'bar@mailgun.net',
is_disposable_address: false,
is_role_address: true,
is_valid: true,
mailbox_verification: 'true',
parts: {
display_name: 'foo',
domain: 'mailgun.net',
local_part: 'foo',
},
};
// Generic requests
mailgun.get('/samples.mailgun.org/stats', (error: any, body: any) => {});
const response1: Promise<any> = mailgun.get('/samples.mailgun.org/stats', { event: ['sent', 'delivered'] });
const response2: Promise<any> = mailgun.get('/samples.mailgun.org/stats');
// Delete mailing list
mailgun.lists('example@mailgun.net').delete((error, body) => { });