|
1 | 1 | import type {Request, Response} from 'express'; |
| 2 | +import {randomUUID} from 'node:crypto'; |
2 | 3 | import {beforeEach, describe, expect, it, vi} from 'vitest'; |
3 | 4 |
|
4 | 5 | import {EmailStatus} from '@plunk/db'; |
@@ -71,10 +72,10 @@ describe('Webhooks - SES event notifications', () => { |
71 | 72 | } |
72 | 73 |
|
73 | 74 | /** Deliver one SES event notification, shaped the way SNS posts it. */ |
74 | | - async function post(event: Record<string, unknown>) { |
| 75 | + async function post(event: Record<string, unknown>, snsMessageId = randomUUID()) { |
75 | 76 | const {res, captured, sent} = mockResponse(); |
76 | 77 | const req = { |
77 | | - body: {Type: 'Notification', Message: JSON.stringify(event)}, |
| 78 | + body: {Type: 'Notification', MessageId: snsMessageId, Message: JSON.stringify(event)}, |
78 | 79 | get: () => undefined, |
79 | 80 | headers: {}, |
80 | 81 | } as unknown as Request; |
@@ -242,8 +243,10 @@ describe('Webhooks - SES event notifications', () => { |
242 | 243 | await sentEmail('ses-campaign-2', campaign.id); |
243 | 244 | await prisma.campaign.update({where: {id: campaign.id}, data: {sentCount: 1}}); |
244 | 245 |
|
245 | | - await post(notification('Delivery', 'ses-campaign-2')); |
246 | | - await post(notification('Delivery', 'ses-campaign-2')); |
| 246 | + const replayedNotification = notification('Delivery', 'ses-campaign-2'); |
| 247 | + const replayedSnsMessageId = randomUUID(); |
| 248 | + await post(replayedNotification, replayedSnsMessageId); |
| 249 | + await post(replayedNotification, replayedSnsMessageId); |
247 | 250 | await CampaignService.sweepDirtyStats(100); |
248 | 251 |
|
249 | 252 | const stats = await CampaignService.getStats(projectId, campaign.id); |
@@ -272,10 +275,10 @@ describe('Webhooks - SES event notifications', () => { |
272 | 275 | expect(updated?.deliveredAt).toBeNull(); |
273 | 276 | }); |
274 | 277 |
|
275 | | - it('404s an event for a messageId it does not know', async () => { |
| 278 | + it('retries an event for a messageId it does not know', async () => { |
276 | 279 | const captured = await post(notification('Delivery', 'ses-never-sent')); |
277 | 280 |
|
278 | | - expect(captured.status).toBe(404); |
| 281 | + expect(captured.status).toBe(500); |
279 | 282 | }); |
280 | 283 | }); |
281 | 284 | }); |
0 commit comments