Skip to content

Commit 98d7cd0

Browse files
fixes
1 parent 5b57155 commit 98d7cd0

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

tests/component-tests/letterQueue-tests/queue-operations.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
} from "tests/helpers/event-fixtures";
77
import { logger } from "tests/helpers/pino-logger";
88
import { sendSnsBatchEvent, sendSnsEvent } from "tests/helpers/send-sns-event";
9-
import { supplierIdFromSupplierAllocatorLog } from "tests/helpers/aws-cloudwatch-helper";
9+
import {
10+
pollUpdateLetterQueueDuplicateLog,
11+
pollUpsertLetterLogForError,
12+
supplierIdFromSupplierAllocatorLog,
13+
} from "tests/helpers/aws-cloudwatch-helper";
1014
import getRestApiGatewayBaseUrl from "tests/helpers/aws-gateway-helper";
1115
import { SUPPLIER_LETTERS } from "tests/constants/api-constants";
1216
import { supplierDataSetup } from "tests/helpers/suppliers-setup-helper";
@@ -85,18 +89,23 @@ test.describe("Letter Queue Tests", () => {
8589
message: event,
8690
})),
8791
);
88-
expect(response.Successful).toBeTruthy();
92+
expect(response.Successful).toHaveLength(eventBatch.length);
8993

9094
const supplierId = await supplierIdFromSupplierAllocatorLog(letterId);
9195

9296
logger.info(
93-
`Verifying if only one entry is inserted in the letter queue table for the batch of events with same letterId ${letterId}`,
97+
`Verifying duplicate queue inserts are ignored for the batch of events with same letterId ${letterId}`,
9498
);
9599
const [letterExists, itemCount] = await checkLetterQueueTable(
96100
supplierId,
97101
letterId,
98102
);
99103
expect(letterExists).toBe(true);
100104
expect(itemCount).toBe(1);
105+
106+
await pollUpsertLetterLogForError(
107+
`Letter with id ${letterId} already exists for supplier ${supplierId}"`,
108+
letterId,
109+
);
101110
});
102111
});

tests/helpers/generate-fetch-test-data.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ export async function checkSupplierExists(
148148

149149
const { Items } = await docClient.send(new QueryCommand(params));
150150
return Items !== undefined && Items.length > 0;
151-
} catch {
151+
} catch (error) {
152+
logger.error({ supplierId, error }, "Supplier existence check failed");
152153
return false;
153154
}
154155
}
@@ -190,7 +191,7 @@ export async function checkLetterQueueTable(
190191
);
191192
return [true, Items.length];
192193
}
193-
if (deleteAfterCheck && Items?.length === 0) {
194+
if (deleteAfterCheck && Items !== undefined && Items.length === 0) {
194195
logger.info(
195196
`Queried letter queue table to verify deletion for letterId ${letterId} and found no items, confirming deletion`,
196197
);

tests/helpers/poll-for-letters-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function pollForLettersInDb(
5858
return pollForLetterStatus(request, supplierId, domainId, baseUrl);
5959
}
6060

61-
export async function pollForLettersInLetterQueue(
61+
export async function getLetterStatusFromApi(
6262
request: APIRequestContext,
6363
supplierId: string,
6464
domainId: string,

tests/helpers/send-sns-event.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export async function sendSnsEvent(
3232
export async function sendSnsBatchEvent(
3333
messages: SnsBatchEventEntry[],
3434
): Promise<PublishBatchCommandOutput> {
35+
if (messages.length > 10) {
36+
throw new Error(
37+
"SNS batch publish supports a maximum of 10 messages per batch",
38+
);
39+
}
3540
const publishBatchRequestEntries: PublishBatchRequestEntry[] = messages.map(
3641
({ id, message, messageAttributes }, index) => ({
3742
Id: id ?? `message-${index + 1}`,

0 commit comments

Comments
 (0)