Skip to content

Commit 1e05212

Browse files
committed
test(webhooks): send complete SNS envelopes
1 parent be437c1 commit 1e05212

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

apps/api/src/controllers/__tests__/Webhooks.sns.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {Request, Response} from 'express';
2+
import {randomUUID} from 'node:crypto';
23
import {beforeEach, describe, expect, it, vi} from 'vitest';
34

45
import {EmailStatus} from '@plunk/db';
@@ -71,10 +72,10 @@ describe('Webhooks - SES event notifications', () => {
7172
}
7273

7374
/** 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()) {
7576
const {res, captured, sent} = mockResponse();
7677
const req = {
77-
body: {Type: 'Notification', Message: JSON.stringify(event)},
78+
body: {Type: 'Notification', MessageId: snsMessageId, Message: JSON.stringify(event)},
7879
get: () => undefined,
7980
headers: {},
8081
} as unknown as Request;
@@ -242,8 +243,10 @@ describe('Webhooks - SES event notifications', () => {
242243
await sentEmail('ses-campaign-2', campaign.id);
243244
await prisma.campaign.update({where: {id: campaign.id}, data: {sentCount: 1}});
244245

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);
247250
await CampaignService.sweepDirtyStats(100);
248251

249252
const stats = await CampaignService.getStats(projectId, campaign.id);
@@ -272,10 +275,10 @@ describe('Webhooks - SES event notifications', () => {
272275
expect(updated?.deliveredAt).toBeNull();
273276
});
274277

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 () => {
276279
const captured = await post(notification('Delivery', 'ses-never-sent'));
277280

278-
expect(captured.status).toBe(404);
281+
expect(captured.status).toBe(500);
279282
});
280283
});
281284
});

0 commit comments

Comments
 (0)