mailgun.js 4.1.6 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,345 @@
1
+ import formData from 'form-data';
2
+
3
+ import nock from 'nock';
4
+ import Request from '../lib/request';
5
+ import RequestOptions from '../lib/interfaces/RequestOptions';
6
+ import { InputFormData } from '../lib/interfaces/IFormData';
7
+ import DomainsTagsClient, { DomainTagStatistic } from '../lib/domainsTags';
8
+ import {
9
+ DomainTagCountriesAggregation,
10
+ DomainTagDevicesAggregation,
11
+ DomainTagProvidersAggregation,
12
+ DomainTagsItem,
13
+ DomainTagsList,
14
+ DomainTagsMessageRes
15
+ } from '../lib/interfaces/DomainTags';
16
+
17
+ describe('DomainsTagsClient', function () {
18
+ let client: DomainsTagsClient;
19
+ let api: nock.Scope;
20
+
21
+ beforeEach(function () {
22
+ const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
23
+ client = new DomainsTagsClient(reqObject);
24
+ api = nock('https://api.mailgun.net');
25
+ });
26
+
27
+ afterEach(function () {
28
+ api.done();
29
+ });
30
+
31
+ describe('list', function () {
32
+ it('fetches all domain tags', function () {
33
+ api.get('/v3/testDomain/tags').reply(200, {
34
+ items: [
35
+ {
36
+ tag: 'tagName',
37
+ description: 'test description',
38
+ 'first-seen': '2020-12-03T00:00:00.000Z',
39
+ 'last-seen': '2021-10-11T17:34:02.297Z'
40
+ },
41
+ {
42
+ tag: 'test1',
43
+ description: 'test description 1',
44
+ 'first-seen': '2020-12-03T01:00:00.000Z',
45
+ 'last-seen': '2021-10-11T18:34:02.297Z'
46
+ },
47
+ {
48
+ tag: 'test2',
49
+ description: 'test description 2',
50
+ 'first-seen': '2020-12-03T02:00:00.000Z',
51
+ 'last-seen': '2021-10-11T19:34:02.297Z'
52
+ }
53
+ ],
54
+ paging: {
55
+ previous: 'https://api.mailgun.net/v3/testDomain/tags?limit=1000&page=prev&tag=',
56
+ first: 'https://api.mailgun.net/v3/testDomain/tags?limit=1000&page=first&tag=',
57
+ next: 'https://api.mailgun.net/v3/testDomain/tags?limit=1000&page=next&tag=',
58
+ last: 'https://api.mailgun.net/v3/testDomain/tags?limit=1000&page=last&tag='
59
+ }
60
+ });
61
+
62
+ return client.list('testDomain').then(function (credentialsList: DomainTagsList) {
63
+ credentialsList.should.be.an('object').to.have.property('items');
64
+ credentialsList.items.should.be.an('array').to.have.property('length').to.be.equal(3);
65
+ credentialsList.items[0].should.eql({
66
+ tag: 'tagName',
67
+ description: 'test description',
68
+ 'first-seen': new Date('2020-12-03T00:00:00.000Z'),
69
+ 'last-seen': new Date('2021-10-11T17:34:02.297Z')
70
+ });
71
+ credentialsList.pages.last.should.eql({
72
+ id: 'last',
73
+ url: 'https://api.mailgun.net/v3/testDomain/tags?limit=1000&page=last&tag='
74
+ });
75
+ });
76
+ });
77
+ });
78
+
79
+ describe('get', function () {
80
+ it('fetches one domain tag', function () {
81
+ api.get('/v3/testDomain/tags/tagName').reply(200, {
82
+ tag: 'tagName',
83
+ description: 'test description',
84
+ 'first-seen': '2020-12-03T00:00:00.000Z',
85
+ 'last-seen': '2021-10-11T17:34:02.297Z'
86
+ });
87
+
88
+ return client.get('testDomain', 'tagName').then(function (tag: DomainTagsItem) {
89
+ tag.should.eql({
90
+ tag: 'tagName',
91
+ description: 'test description',
92
+ 'first-seen': new Date('2020-12-03T00:00:00.000Z'),
93
+ 'last-seen': new Date('2021-10-11T17:34:02.297Z')
94
+ });
95
+ });
96
+ });
97
+ });
98
+
99
+ describe('update', function () {
100
+ it('updates domain tags', function () {
101
+ api.put('/v3/testDomain/tags/tagName').reply(200, {
102
+ message: 'Tag updated'
103
+ });
104
+
105
+ return client.update('testDomain', 'tagName', 'new Description').then(function (res: DomainTagsMessageRes) {
106
+ res.should.eql({ message: 'Tag updated' });
107
+ });
108
+ });
109
+ });
110
+
111
+ describe('destroy', function () {
112
+ it('deletes a domain tags', function () {
113
+ api.delete('/v3/testDomain/tags/tagName').reply(200, {
114
+ message: 'Tag deleted'
115
+ });
116
+
117
+ return client.destroy('testDomain', 'tagName').then(function (data: DomainTagsMessageRes) {
118
+ data.should.eql({
119
+ message: 'Tag deleted',
120
+ status: 200
121
+ });
122
+ });
123
+ });
124
+ });
125
+
126
+ describe('statistic', function () {
127
+ it('returns statistic for a tag', function () {
128
+ api.get('/v3/testDomain/tags/tagName/stats?event=stored').reply(200, {
129
+ tag: 'tagName',
130
+ description: 'test description',
131
+ start: 'Mon, 24 Jan 2022 00:00:00 UTC',
132
+ end: 'Mon, 31 Jan 2022 00:00:00 UTC',
133
+ resolution: 'day',
134
+ stats: [
135
+ { time: 'Mon, 24 Jan 2022 00:00:00 UTC', stored: { total: 0 } },
136
+ { time: 'Tue, 25 Jan 2022 00:00:00 UTC', stored: { total: 0 } },
137
+ ]
138
+ });
139
+
140
+ return client.statistic('testDomain', 'tagName', { event: 'stored' }).then(function (data: DomainTagStatistic) {
141
+ data.should.eql({
142
+ tag: 'tagName',
143
+ description: 'test description',
144
+ start: new Date('Mon, 24 Jan 2022 00:00:00 UTC'),
145
+ end: new Date('Mon, 31 Jan 2022 00:00:00 UTC'),
146
+ resolution: 'day',
147
+ stats: [
148
+ { time: new Date('Mon, 24 Jan 2022 00:00:00 UTC'), stored: { total: 0 } },
149
+ { time: new Date('Tue, 25 Jan 2022 00:00:00 UTC'), stored: { total: 0 } },
150
+ ]
151
+ });
152
+ });
153
+ });
154
+ });
155
+
156
+ describe('countries', function () {
157
+ it('returns statistic by countries for a tag', function () {
158
+ api.get('/v3/testDomain/tags/tagName/stats/aggregates/countries').reply(200, {
159
+ country: {
160
+ ad: {
161
+ clicked: 0,
162
+ complained: 0,
163
+ opened: 0,
164
+ unique_clicked: 0,
165
+ unique_opened: 0,
166
+ unsubscribed: 0
167
+ },
168
+ ae: {
169
+ clicked: 0,
170
+ complained: 0,
171
+ opened: 0,
172
+ unique_clicked: 0,
173
+ unique_opened: 0,
174
+ unsubscribed: 0
175
+ }
176
+ },
177
+ tag: 'tagName'
178
+ });
179
+
180
+ return client.countries('testDomain', 'tagName').then(function (data: DomainTagCountriesAggregation) {
181
+ data.should.eql({
182
+ tag: 'tagName',
183
+ country: {
184
+ ad: {
185
+ clicked: 0,
186
+ complained: 0,
187
+ opened: 0,
188
+ unique_clicked: 0,
189
+ unique_opened: 0,
190
+ unsubscribed: 0
191
+ },
192
+ ae: {
193
+ clicked: 0,
194
+ complained: 0,
195
+ opened: 0,
196
+ unique_clicked: 0,
197
+ unique_opened: 0,
198
+ unsubscribed: 0
199
+ }
200
+ }
201
+ });
202
+ });
203
+ });
204
+ });
205
+
206
+ describe('providers', function () {
207
+ it('returns statistic by providers for a tag', function () {
208
+ api.get('/v3/testDomain/tags/tagName/stats/aggregates/providers').reply(200, {
209
+ provider: {
210
+ 'gmail.com': {
211
+ accepted: 126,
212
+ clicked: 0,
213
+ complained: 0,
214
+ delivered: 126,
215
+ opened: 0,
216
+ unique_clicked: 0,
217
+ unique_opened: 0,
218
+ unsubscribed: 0
219
+ },
220
+ 'aol.com': {
221
+ accepted: 0,
222
+ clicked: 0,
223
+ complained: 0,
224
+ delivered: 0,
225
+ opened: 0,
226
+ unique_clicked: 0,
227
+ unique_opened: 0,
228
+ unsubscribed: 0
229
+ },
230
+ },
231
+ tag: 'tagName'
232
+ });
233
+
234
+ return client.providers('testDomain', 'tagName').then(function (data: DomainTagProvidersAggregation) {
235
+ data.should.eql({
236
+ tag: 'tagName',
237
+ provider: {
238
+ 'gmail.com': {
239
+ accepted: 126,
240
+ clicked: 0,
241
+ complained: 0,
242
+ delivered: 126,
243
+ opened: 0,
244
+ unique_clicked: 0,
245
+ unique_opened: 0,
246
+ unsubscribed: 0
247
+ },
248
+ 'aol.com': {
249
+ accepted: 0,
250
+ clicked: 0,
251
+ complained: 0,
252
+ delivered: 0,
253
+ opened: 0,
254
+ unique_clicked: 0,
255
+ unique_opened: 0,
256
+ unsubscribed: 0
257
+ },
258
+ }
259
+ });
260
+ });
261
+ });
262
+ });
263
+
264
+ describe('providers', function () {
265
+ it('returns statistic by devices for a tag', function () {
266
+ api.get('/v3/testDomain/tags/tagName/stats/aggregates/devices').reply(200, {
267
+ device: {
268
+ desktop: {
269
+ clicked: 0,
270
+ complained: 0,
271
+ opened: 0,
272
+ unique_clicked: 0,
273
+ unique_opened: 0,
274
+ unsubscribed: 0
275
+ },
276
+ mobile: {
277
+ clicked: 0,
278
+ complained: 0,
279
+ opened: 0,
280
+ unique_clicked: 0,
281
+ unique_opened: 0,
282
+ unsubscribed: 0
283
+ },
284
+ tablet: {
285
+ clicked: 0,
286
+ complained: 0,
287
+ opened: 0,
288
+ unique_clicked: 0,
289
+ unique_opened: 0,
290
+ unsubscribed: 0
291
+ },
292
+ unknown: {
293
+ clicked: 0,
294
+ complained: 0,
295
+ opened: 0,
296
+ unique_clicked: 0,
297
+ unique_opened: 0,
298
+ unsubscribed: 0
299
+ }
300
+ },
301
+ tag: 'tagName'
302
+ });
303
+
304
+ return client.devices('testDomain', 'tagName').then(function (data: DomainTagDevicesAggregation) {
305
+ data.should.eql({
306
+ tag: 'tagName',
307
+ device: {
308
+ desktop: {
309
+ clicked: 0,
310
+ complained: 0,
311
+ opened: 0,
312
+ unique_clicked: 0,
313
+ unique_opened: 0,
314
+ unsubscribed: 0
315
+ },
316
+ mobile: {
317
+ clicked: 0,
318
+ complained: 0,
319
+ opened: 0,
320
+ unique_clicked: 0,
321
+ unique_opened: 0,
322
+ unsubscribed: 0
323
+ },
324
+ tablet: {
325
+ clicked: 0,
326
+ complained: 0,
327
+ opened: 0,
328
+ unique_clicked: 0,
329
+ unique_opened: 0,
330
+ unsubscribed: 0
331
+ },
332
+ unknown: {
333
+ clicked: 0,
334
+ complained: 0,
335
+ opened: 0,
336
+ unique_clicked: 0,
337
+ unique_opened: 0,
338
+ unsubscribed: 0
339
+ }
340
+ }
341
+ });
342
+ });
343
+ });
344
+ });
345
+ });