@stamhoofd/models 2.91.0 → 2.93.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.
- package/dist/src/factories/RegistrationPeriodFactory.d.ts +2 -1
- package/dist/src/factories/RegistrationPeriodFactory.d.ts.map +1 -1
- package/dist/src/factories/RegistrationPeriodFactory.js +2 -1
- package/dist/src/factories/RegistrationPeriodFactory.js.map +1 -1
- package/dist/src/helpers/EmailBuilder.d.ts +1 -2
- package/dist/src/helpers/EmailBuilder.d.ts.map +1 -1
- package/dist/src/helpers/EmailBuilder.js +7 -21
- package/dist/src/helpers/EmailBuilder.js.map +1 -1
- package/dist/src/helpers/MemberMerger.d.ts.map +1 -1
- package/dist/src/helpers/MemberMerger.js +6 -0
- package/dist/src/helpers/MemberMerger.js.map +1 -1
- package/dist/src/migrations/1755529026-email-sender-id.sql +2 -0
- package/dist/src/migrations/1755789797-email-counts-errors.sql +7 -0
- package/dist/src/migrations/1755789798-email-recipient-errors.sql +2 -0
- package/dist/src/migrations/1756115313-email-recipient-ids-and-errors.sql +10 -0
- package/dist/src/migrations/1756115314-email-recipient-email-optional.sql +2 -0
- package/dist/src/migrations/1756115315-email-recipients-count.sql +3 -0
- package/dist/src/migrations/1756115316-email-cached-counts.sql +4 -0
- package/dist/src/models/Email.d.ts +63 -2
- package/dist/src/models/Email.d.ts.map +1 -1
- package/dist/src/models/Email.js +559 -194
- package/dist/src/models/Email.js.map +1 -1
- package/dist/src/models/Email.test.js +151 -43
- package/dist/src/models/Email.test.js.map +1 -1
- package/dist/src/models/EmailRecipient.d.ts +31 -1
- package/dist/src/models/EmailRecipient.d.ts.map +1 -1
- package/dist/src/models/EmailRecipient.js +53 -2
- package/dist/src/models/EmailRecipient.js.map +1 -1
- package/dist/src/models/WebshopUitpasNumber.d.ts +2 -1
- package/dist/src/models/WebshopUitpasNumber.d.ts.map +1 -1
- package/dist/src/models/WebshopUitpasNumber.js +20 -3
- package/dist/src/models/WebshopUitpasNumber.js.map +1 -1
- package/package.json +2 -2
- package/src/factories/RegistrationPeriodFactory.ts +3 -2
- package/src/helpers/EmailBuilder.ts +9 -24
- package/src/helpers/MemberMerger.ts +7 -0
- package/src/migrations/1755529026-email-sender-id.sql +2 -0
- package/src/migrations/1755789797-email-counts-errors.sql +7 -0
- package/src/migrations/1755789798-email-recipient-errors.sql +2 -0
- package/src/migrations/1756115313-email-recipient-ids-and-errors.sql +10 -0
- package/src/migrations/1756115314-email-recipient-email-optional.sql +2 -0
- package/src/migrations/1756115315-email-recipients-count.sql +3 -0
- package/src/migrations/1756115316-email-cached-counts.sql +4 -0
- package/src/models/Email.test.ts +165 -44
- package/src/models/Email.ts +639 -207
- package/src/models/EmailRecipient.ts +46 -2
- package/src/models/WebshopUitpasNumber.ts +23 -3
package/src/models/Email.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { EmailRecipientFilter, EmailRecipientFilterType, EmailRecipientsStatus,
|
|
|
2
2
|
import { Email } from './Email';
|
|
3
3
|
import { EmailRecipient } from './EmailRecipient';
|
|
4
4
|
import { EmailMocker } from '@stamhoofd/email';
|
|
5
|
-
import { TestUtils } from '@stamhoofd/test-utils';
|
|
5
|
+
import { STExpect, TestUtils } from '@stamhoofd/test-utils';
|
|
6
6
|
import { OrganizationFactory } from '../factories/OrganizationFactory';
|
|
7
7
|
import { Platform } from './Platform';
|
|
8
8
|
|
|
@@ -50,6 +50,48 @@ async function buildEmail(data: {
|
|
|
50
50
|
return model;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* An email that won't be able to fetch recipients
|
|
55
|
+
*/
|
|
56
|
+
async function buildFailEmail(data: {
|
|
57
|
+
recipients: EmailRecipientStruct[];
|
|
58
|
+
} & Partial<Email>) {
|
|
59
|
+
Email.recipientLoaders.set(EmailRecipientFilterType.Members, {
|
|
60
|
+
fetch: async (query: LimitedFilteredRequest) => {
|
|
61
|
+
throw new Error('This is a simulated error while fetching recipients');
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
count: async (query: LimitedFilteredRequest) => {
|
|
65
|
+
return data.recipients.length;
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const model = new Email();
|
|
70
|
+
model.userId = null;
|
|
71
|
+
model.organizationId = data.organizationId ?? null;
|
|
72
|
+
model.recipientFilter = EmailRecipientFilter.create({
|
|
73
|
+
filters: [
|
|
74
|
+
EmailRecipientSubfilter.create({
|
|
75
|
+
type: EmailRecipientFilterType.Members,
|
|
76
|
+
filter: { id: { $in: ['test'] } },
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
model.subject = data.subject ?? 'This is a test email';
|
|
82
|
+
model.html = data.html ?? '<p>This is a test email</p>';
|
|
83
|
+
model.text = data.text ?? 'This is a test email';
|
|
84
|
+
model.json = data.json ?? {};
|
|
85
|
+
model.status = data.status ?? EmailStatus.Draft;
|
|
86
|
+
model.attachments = [];
|
|
87
|
+
model.fromAddress = data.fromAddress ?? 'test@stamhoofd.be';
|
|
88
|
+
model.fromName = data.fromName ?? null;
|
|
89
|
+
|
|
90
|
+
await model.save();
|
|
91
|
+
|
|
92
|
+
return model;
|
|
93
|
+
}
|
|
94
|
+
|
|
53
95
|
describe('Model.Email', () => {
|
|
54
96
|
it('Correctly whitelists email recipients', async () => {
|
|
55
97
|
TestUtils.setEnvironment('WHITELISTED_EMAIL_DESTINATIONS', ['*@stamhoofd-allowed-domain-tests.be']);
|
|
@@ -67,12 +109,16 @@ describe('Model.Email', () => {
|
|
|
67
109
|
}),
|
|
68
110
|
],
|
|
69
111
|
});
|
|
70
|
-
await model.
|
|
112
|
+
await model.queueForSending(true);
|
|
71
113
|
await model.refresh();
|
|
72
114
|
|
|
73
115
|
// Check if it was sent correctly
|
|
74
116
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
75
|
-
expect(model.
|
|
117
|
+
expect(model.emailRecipientsCount).toBe(2);
|
|
118
|
+
expect(model.succeededCount).toBe(1);
|
|
119
|
+
expect(model.failedCount).toBe(1);
|
|
120
|
+
expect(model.emailErrors).toBe(null);
|
|
121
|
+
expect(model.recipientsErrors).toBe(null);
|
|
76
122
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
77
123
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
78
124
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0); // never tried to send any failed emails (whitelist)
|
|
@@ -119,13 +165,16 @@ describe('Model.Email', () => {
|
|
|
119
165
|
// It should automatically retry to send the email
|
|
120
166
|
EmailMocker.broadcast.failNext(new Error('This is a simulated network error'));
|
|
121
167
|
|
|
122
|
-
await model.
|
|
168
|
+
await model.queueForSending(true);
|
|
123
169
|
await model.refresh();
|
|
124
170
|
|
|
125
171
|
// Check if it was sent correctly
|
|
126
172
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
127
|
-
expect(model.
|
|
173
|
+
expect(model.emailRecipientsCount).toBe(2);
|
|
128
174
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
175
|
+
expect(model.succeededCount).toBe(2);
|
|
176
|
+
expect(model.failedCount).toBe(0);
|
|
177
|
+
expect(model.softFailedCount).toBe(0);
|
|
129
178
|
|
|
130
179
|
// Both have succeeded
|
|
131
180
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(2);
|
|
@@ -147,6 +196,43 @@ describe('Model.Email', () => {
|
|
|
147
196
|
]);
|
|
148
197
|
}, 15_000);
|
|
149
198
|
|
|
199
|
+
it('Email changes to failed state if email recipients fails to build', async () => {
|
|
200
|
+
const model = await buildFailEmail({
|
|
201
|
+
recipients: [
|
|
202
|
+
EmailRecipientStruct.create({
|
|
203
|
+
firstName: 'Test',
|
|
204
|
+
lastName: 'Test',
|
|
205
|
+
email: 'example@domain.be',
|
|
206
|
+
}),
|
|
207
|
+
EmailRecipientStruct.create({
|
|
208
|
+
firstName: 'Test',
|
|
209
|
+
lastName: 'Test',
|
|
210
|
+
email: 'example2@domain.be',
|
|
211
|
+
}),
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
await expect(model.queueForSending(true)).toReject();
|
|
216
|
+
await model.refresh();
|
|
217
|
+
|
|
218
|
+
// Check if it was sent correctly
|
|
219
|
+
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.NotCreated);
|
|
220
|
+
expect(model.recipientsErrors).toEqual(STExpect.simpleErrors([{
|
|
221
|
+
code: 'unknown_error',
|
|
222
|
+
message: 'This is a simulated error while fetching recipients',
|
|
223
|
+
}]));
|
|
224
|
+
|
|
225
|
+
expect(model.emailRecipientsCount).toBe(null);
|
|
226
|
+
expect(model.status).toBe(EmailStatus.Failed);
|
|
227
|
+
expect(model.succeededCount).toBe(0);
|
|
228
|
+
expect(model.failedCount).toBe(0);
|
|
229
|
+
expect(model.softFailedCount).toBe(0);
|
|
230
|
+
|
|
231
|
+
// Both have succeeded
|
|
232
|
+
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(0);
|
|
233
|
+
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0); // One retry
|
|
234
|
+
}, 15_000);
|
|
235
|
+
|
|
150
236
|
it('Marks email recipient as failed if fails three times', async () => {
|
|
151
237
|
const model = await buildEmail({
|
|
152
238
|
recipients: [
|
|
@@ -163,8 +249,6 @@ describe('Model.Email', () => {
|
|
|
163
249
|
],
|
|
164
250
|
});
|
|
165
251
|
|
|
166
|
-
// Only one failure (the first email)
|
|
167
|
-
// It should automatically retry to send the email
|
|
168
252
|
EmailMocker.broadcast.failNext(new Error('This is a simulated network error 1'));
|
|
169
253
|
EmailMocker.broadcast.failNext(new Error('This is a simulated network error 2'));
|
|
170
254
|
EmailMocker.broadcast.failNext(new Error('This is a simulated network error 3'));
|
|
@@ -172,13 +256,16 @@ describe('Model.Email', () => {
|
|
|
172
256
|
EmailMocker.broadcast.failNext(new Error('This is a simulated network error 5'));
|
|
173
257
|
EmailMocker.broadcast.failNext(new Error('This is a simulated network error 6'));
|
|
174
258
|
|
|
175
|
-
await model.
|
|
259
|
+
await model.queueForSending(true);
|
|
176
260
|
await model.refresh();
|
|
177
261
|
|
|
178
262
|
// Check if it was sent correctly
|
|
179
263
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
180
|
-
expect(model.
|
|
264
|
+
expect(model.emailRecipientsCount).toBe(2);
|
|
181
265
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
266
|
+
expect(model.succeededCount).toBe(0);
|
|
267
|
+
expect(model.failedCount).toBe(2);
|
|
268
|
+
expect(model.softFailedCount).toBe(0);
|
|
182
269
|
|
|
183
270
|
// Both have succeeded
|
|
184
271
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(0);
|
|
@@ -191,6 +278,9 @@ describe('Model.Email', () => {
|
|
|
191
278
|
email: 'example@domain.be',
|
|
192
279
|
sentAt: null,
|
|
193
280
|
failCount: 1,
|
|
281
|
+
failError: STExpect.simpleErrors([{
|
|
282
|
+
message: /This is a simulated network error (3|6)/,
|
|
283
|
+
}]),
|
|
194
284
|
firstFailedAt: expect.any(Date),
|
|
195
285
|
lastFailedAt: expect.any(Date),
|
|
196
286
|
}),
|
|
@@ -198,6 +288,9 @@ describe('Model.Email', () => {
|
|
|
198
288
|
email: 'example2@domain.be',
|
|
199
289
|
sentAt: null,
|
|
200
290
|
failCount: 1,
|
|
291
|
+
failError: STExpect.simpleErrors([{
|
|
292
|
+
message: /This is a simulated network error (3|6)/,
|
|
293
|
+
}]),
|
|
201
294
|
firstFailedAt: expect.any(Date),
|
|
202
295
|
lastFailedAt: expect.any(Date),
|
|
203
296
|
}),
|
|
@@ -213,13 +306,16 @@ describe('Model.Email', () => {
|
|
|
213
306
|
],
|
|
214
307
|
});
|
|
215
308
|
|
|
216
|
-
await model.
|
|
309
|
+
await model.queueForSending(true);
|
|
217
310
|
await model.refresh();
|
|
218
311
|
|
|
219
312
|
// Check if it was sent correctly
|
|
220
313
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
221
|
-
expect(model.
|
|
314
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
222
315
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
316
|
+
expect(model.succeededCount).toBe(1);
|
|
317
|
+
expect(model.failedCount).toBe(0);
|
|
318
|
+
expect(model.softFailedCount).toBe(0);
|
|
223
319
|
|
|
224
320
|
// Both have succeeded
|
|
225
321
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
@@ -236,7 +332,7 @@ describe('Model.Email', () => {
|
|
|
236
332
|
]);
|
|
237
333
|
|
|
238
334
|
// Check to header
|
|
239
|
-
expect(
|
|
335
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0).to).toEqual('example@domain.be');
|
|
240
336
|
}, 15_000);
|
|
241
337
|
|
|
242
338
|
it('Includes recipient names in mail header', async () => {
|
|
@@ -250,13 +346,16 @@ describe('Model.Email', () => {
|
|
|
250
346
|
],
|
|
251
347
|
});
|
|
252
348
|
|
|
253
|
-
await model.
|
|
349
|
+
await model.queueForSending(true);
|
|
254
350
|
await model.refresh();
|
|
255
351
|
|
|
256
352
|
// Check if it was sent correctly
|
|
257
353
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
258
|
-
expect(model.
|
|
354
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
259
355
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
356
|
+
expect(model.succeededCount).toBe(1);
|
|
357
|
+
expect(model.failedCount).toBe(0);
|
|
358
|
+
expect(model.softFailedCount).toBe(0);
|
|
260
359
|
|
|
261
360
|
// Both have succeeded
|
|
262
361
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
@@ -275,7 +374,7 @@ describe('Model.Email', () => {
|
|
|
275
374
|
]);
|
|
276
375
|
|
|
277
376
|
// Check to header
|
|
278
|
-
expect(
|
|
377
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0).to).toEqual('"John Von Doe" <example@domain.be>');
|
|
279
378
|
}, 15_000);
|
|
280
379
|
|
|
281
380
|
it('Skips invalid email addresses', async () => {
|
|
@@ -289,13 +388,16 @@ describe('Model.Email', () => {
|
|
|
289
388
|
],
|
|
290
389
|
});
|
|
291
390
|
|
|
292
|
-
await model.
|
|
391
|
+
await model.queueForSending(true);
|
|
293
392
|
await model.refresh();
|
|
294
393
|
|
|
295
394
|
// Check if it was sent correctly
|
|
296
395
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
297
|
-
expect(model.
|
|
396
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
298
397
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
398
|
+
expect(model.succeededCount).toBe(0);
|
|
399
|
+
expect(model.failedCount).toBe(1);
|
|
400
|
+
expect(model.softFailedCount).toBe(0);
|
|
299
401
|
|
|
300
402
|
// Both have succeeded
|
|
301
403
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(0);
|
|
@@ -309,7 +411,10 @@ describe('Model.Email', () => {
|
|
|
309
411
|
lastName: 'Von Doe',
|
|
310
412
|
email: 'invalid',
|
|
311
413
|
failCount: 1,
|
|
312
|
-
|
|
414
|
+
failError: STExpect.simpleErrors([{
|
|
415
|
+
code: 'invalid_email_address',
|
|
416
|
+
message: 'Invalid email address',
|
|
417
|
+
}]),
|
|
313
418
|
firstFailedAt: expect.any(Date),
|
|
314
419
|
lastFailedAt: expect.any(Date),
|
|
315
420
|
}),
|
|
@@ -332,13 +437,16 @@ describe('Model.Email', () => {
|
|
|
332
437
|
],
|
|
333
438
|
});
|
|
334
439
|
|
|
335
|
-
await model.
|
|
440
|
+
await model.queueForSending(true);
|
|
336
441
|
await model.refresh();
|
|
337
442
|
|
|
338
443
|
// Check if it was sent correctly
|
|
339
444
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
340
|
-
expect(model.
|
|
445
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
341
446
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
447
|
+
expect(model.succeededCount).toBe(1);
|
|
448
|
+
expect(model.failedCount).toBe(0);
|
|
449
|
+
expect(model.softFailedCount).toBe(0);
|
|
342
450
|
|
|
343
451
|
// Both have succeeded
|
|
344
452
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
@@ -350,6 +458,7 @@ describe('Model.Email', () => {
|
|
|
350
458
|
expect.objectContaining({
|
|
351
459
|
email: 'valid@example.com',
|
|
352
460
|
sentAt: expect.any(Date),
|
|
461
|
+
failError: null,
|
|
353
462
|
}),
|
|
354
463
|
]);
|
|
355
464
|
}, 15_000);
|
|
@@ -375,20 +484,23 @@ describe('Model.Email', () => {
|
|
|
375
484
|
fromName: 'My Platform',
|
|
376
485
|
});
|
|
377
486
|
|
|
378
|
-
await model.
|
|
487
|
+
await model.queueForSending(true);
|
|
379
488
|
await model.refresh();
|
|
380
489
|
|
|
381
490
|
// Check if it was sent correctly
|
|
382
491
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
383
|
-
expect(model.
|
|
492
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
384
493
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
494
|
+
expect(model.succeededCount).toBe(1);
|
|
495
|
+
expect(model.failedCount).toBe(0);
|
|
496
|
+
expect(model.softFailedCount).toBe(0);
|
|
385
497
|
|
|
386
498
|
// Both have succeeded
|
|
387
499
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
388
500
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
389
501
|
|
|
390
502
|
// Check to header
|
|
391
|
-
expect(
|
|
503
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
392
504
|
to: 'example@domain.be',
|
|
393
505
|
from: '"My Platform" <info@my-platform.com>',
|
|
394
506
|
replyTo: undefined,
|
|
@@ -416,20 +528,23 @@ describe('Model.Email', () => {
|
|
|
416
528
|
fromName: 'My Platform',
|
|
417
529
|
});
|
|
418
530
|
|
|
419
|
-
await model.
|
|
531
|
+
await model.queueForSending(true);
|
|
420
532
|
await model.refresh();
|
|
421
533
|
|
|
422
534
|
// Check if it was sent correctly
|
|
423
535
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
424
|
-
expect(model.
|
|
536
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
425
537
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
538
|
+
expect(model.succeededCount).toBe(1);
|
|
539
|
+
expect(model.failedCount).toBe(0);
|
|
540
|
+
expect(model.softFailedCount).toBe(0);
|
|
426
541
|
|
|
427
542
|
// Both have succeeded
|
|
428
543
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
429
544
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
430
545
|
|
|
431
546
|
// Check to header
|
|
432
|
-
expect(
|
|
547
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
433
548
|
to: 'example@domain.be',
|
|
434
549
|
from: '"My Platform" <noreply@broadcast.my-platform.com>', // domain has changed here
|
|
435
550
|
replyTo: '"My Platform" <info@other-platform.com>', // Reply to should be set
|
|
@@ -462,20 +577,23 @@ describe('Model.Email', () => {
|
|
|
462
577
|
fromName: 'My Platform',
|
|
463
578
|
});
|
|
464
579
|
|
|
465
|
-
await model.
|
|
580
|
+
await model.queueForSending(true);
|
|
466
581
|
await model.refresh();
|
|
467
582
|
|
|
468
583
|
// Check if it was sent correctly
|
|
469
584
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
470
|
-
expect(model.
|
|
585
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
471
586
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
587
|
+
expect(model.succeededCount).toBe(1);
|
|
588
|
+
expect(model.failedCount).toBe(0);
|
|
589
|
+
expect(model.softFailedCount).toBe(0);
|
|
472
590
|
|
|
473
591
|
// Both have succeeded
|
|
474
592
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
475
593
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
476
594
|
|
|
477
595
|
// Check to header
|
|
478
|
-
expect(
|
|
596
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
479
597
|
to: 'example@domain.be',
|
|
480
598
|
from: '"My Platform" <noreply-uritest@broadcast.my-platform.com>', // domain has changed here
|
|
481
599
|
replyTo: '"My Platform" <info@my-platform.com>', // Reply to should be set
|
|
@@ -510,20 +628,23 @@ describe('Model.Email', () => {
|
|
|
510
628
|
fromName: 'My Platform',
|
|
511
629
|
});
|
|
512
630
|
|
|
513
|
-
await model.
|
|
631
|
+
await model.queueForSending(true);
|
|
514
632
|
await model.refresh();
|
|
515
633
|
|
|
516
634
|
// Check if it was sent correctly
|
|
517
635
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
518
|
-
expect(model.
|
|
636
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
519
637
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
638
|
+
expect(model.succeededCount).toBe(1);
|
|
639
|
+
expect(model.failedCount).toBe(0);
|
|
640
|
+
expect(model.softFailedCount).toBe(0);
|
|
520
641
|
|
|
521
642
|
// Both have succeeded
|
|
522
643
|
expect(await EmailMocker.broadcast.getSucceededCount()).toBe(1);
|
|
523
644
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
524
645
|
|
|
525
646
|
// Check to header
|
|
526
|
-
expect(
|
|
647
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
527
648
|
to: 'example@domain.be',
|
|
528
649
|
from: '"My Platform" <info@my-platform.com>', // domain has changed here
|
|
529
650
|
replyTo: undefined,
|
|
@@ -558,12 +679,12 @@ describe('Model.Email', () => {
|
|
|
558
679
|
subject: '{{fromAddress}}',
|
|
559
680
|
});
|
|
560
681
|
|
|
561
|
-
await model.
|
|
682
|
+
await model.queueForSending(true);
|
|
562
683
|
await model.refresh();
|
|
563
684
|
|
|
564
685
|
// Check if it was sent correctly
|
|
565
686
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
566
|
-
expect(model.
|
|
687
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
567
688
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
568
689
|
|
|
569
690
|
// Both have succeeded
|
|
@@ -571,7 +692,7 @@ describe('Model.Email', () => {
|
|
|
571
692
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
572
693
|
|
|
573
694
|
// Check to header
|
|
574
|
-
expect(
|
|
695
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
575
696
|
to: 'example@domain.be',
|
|
576
697
|
from: '"Custom Name" <noreply-' + organization.uri + '@broadcast.my-platform.com>',
|
|
577
698
|
replyTo: '"Custom Name" <custom@customdomain.com>', // domain has changed here
|
|
@@ -614,12 +735,12 @@ describe('Model.Email', () => {
|
|
|
614
735
|
subject: '{{primaryColor}};{{primaryColorContrast}};{{organizationName}};{{fromName}}',
|
|
615
736
|
});
|
|
616
737
|
|
|
617
|
-
await model.
|
|
738
|
+
await model.queueForSending(true);
|
|
618
739
|
await model.refresh();
|
|
619
740
|
|
|
620
741
|
// Check if it was sent correctly
|
|
621
742
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
622
|
-
expect(model.
|
|
743
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
623
744
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
624
745
|
|
|
625
746
|
// Both have succeeded
|
|
@@ -627,7 +748,7 @@ describe('Model.Email', () => {
|
|
|
627
748
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
628
749
|
|
|
629
750
|
// Check to header
|
|
630
|
-
expect(
|
|
751
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
631
752
|
subject: `${brightYellow};${expectedContrastColor};${organization.name};${organization.name}`,
|
|
632
753
|
html: `${brightYellow};${expectedContrastColor};${organization.name};${organization.name}`,
|
|
633
754
|
text: `${brightYellow};${expectedContrastColor};${organization.name};${organization.name}`,
|
|
@@ -672,12 +793,12 @@ describe('Model.Email', () => {
|
|
|
672
793
|
subject: '{{primaryColor}};{{primaryColorContrast}};{{organizationName}};{{fromName}}',
|
|
673
794
|
});
|
|
674
795
|
|
|
675
|
-
await model.
|
|
796
|
+
await model.queueForSending(true);
|
|
676
797
|
await model.refresh();
|
|
677
798
|
|
|
678
799
|
// Check if it was sent correctly
|
|
679
800
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
680
|
-
expect(model.
|
|
801
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
681
802
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
682
803
|
|
|
683
804
|
// Both have succeeded
|
|
@@ -685,7 +806,7 @@ describe('Model.Email', () => {
|
|
|
685
806
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
686
807
|
|
|
687
808
|
// Check to header
|
|
688
|
-
expect(
|
|
809
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
689
810
|
subject: `${brightBlue};${expectedContrastColor};${organization.name};Custom Name`,
|
|
690
811
|
html: `${brightBlue};${expectedContrastColor};${organization.name};Custom Name`,
|
|
691
812
|
text: `${brightBlue};${expectedContrastColor};${organization.name};Custom Name`,
|
|
@@ -722,12 +843,12 @@ describe('Model.Email', () => {
|
|
|
722
843
|
subject: '{{primaryColor}};{{primaryColorContrast}};{{organizationName}};{{fromName}}',
|
|
723
844
|
});
|
|
724
845
|
|
|
725
|
-
await model.
|
|
846
|
+
await model.queueForSending(true);
|
|
726
847
|
await model.refresh();
|
|
727
848
|
|
|
728
849
|
// Check if it was sent correctly
|
|
729
850
|
expect(model.recipientsStatus).toBe(EmailRecipientsStatus.Created);
|
|
730
|
-
expect(model.
|
|
851
|
+
expect(model.emailRecipientsCount).toBe(1);
|
|
731
852
|
expect(model.status).toBe(EmailStatus.Sent);
|
|
732
853
|
|
|
733
854
|
// Both have succeeded
|
|
@@ -735,7 +856,7 @@ describe('Model.Email', () => {
|
|
|
735
856
|
expect(await EmailMocker.broadcast.getFailedCount()).toBe(0);
|
|
736
857
|
|
|
737
858
|
// Check to header
|
|
738
|
-
expect(
|
|
859
|
+
expect(EmailMocker.broadcast.getSucceededEmail(0)).toMatchObject({
|
|
739
860
|
subject: `${darkRed};${expectedContrastColor};${platform.config.name};${platform.config.name}`,
|
|
740
861
|
html: `${darkRed};${expectedContrastColor};${platform.config.name};${platform.config.name}`,
|
|
741
862
|
text: `${darkRed};${expectedContrastColor};${platform.config.name};${platform.config.name}`,
|