diff --git a/src/functions/certGenInit.ts b/src/functions/certGenInit.ts index 447150b..903522a 100644 --- a/src/functions/certGenInit.ts +++ b/src/functions/certGenInit.ts @@ -48,14 +48,10 @@ const certGenInit: Handler = async ( for (const record of certGenFilteredRecords) { const stringifiedRecord = JSON.stringify(record); console.log(stringifiedRecord); - Promise.resolve(sqService.sendCertGenMessage(stringifiedRecord)).then( - () => { - console.log( - `event ${record.dynamodb?.SequenceNumber} successfully processed` - ); - } - ); + await sqService.sendCertGenMessage(stringifiedRecord); } + + console.log(`event ${record.dynamodb?.SequenceNumber} successfully processed`); } catch (err) { console.error(err); console.log("expandedRecords"); diff --git a/src/services/SQService.ts b/src/services/SQService.ts index 25349da..2b0c4cc 100644 --- a/src/services/SQService.ts +++ b/src/services/SQService.ts @@ -8,8 +8,7 @@ import { ReceiveMessageCommandOutput, SQSClient, SendMessageCommand, - SendMessageCommandInput, - SendMessageCommandOutput, + SendMessageCommandInput } from "@aws-sdk/client-sqs"; import { Service } from "../models/injector/ServiceDecorator"; @@ -68,7 +67,7 @@ class SQService { messageBody: string, queueName: string, messageAttributes?: Record - ): Promise { + ) { // Get the queue URL for the provided queue name const queueUrlResult: GetQueueUrlCommandOutput = await this.sqsClient.send( new GetQueueUrlCommand({ QueueName: queueName }) @@ -85,7 +84,7 @@ class SQService { } // Send a message to the queue - return this.sqsClient.send( + await this.sqsClient.send( new SendMessageCommand(params as SendMessageCommandInput) ); } diff --git a/tests/unit/certGenInitFunction.unitTest.ts b/tests/unit/certGenInitFunction.unitTest.ts index c98a1a4..f43599c 100644 --- a/tests/unit/certGenInitFunction.unitTest.ts +++ b/tests/unit/certGenInitFunction.unitTest.ts @@ -65,18 +65,15 @@ describe("certGenInit Function", () => { .mockReturnValue([{ test: "thing" }]); expect.assertions(1); - try { - const returnedInfo = await certGenInit( - { Records: ["this is an event"] }, - ctx, - () => { - return; - } - ); - expect(returnedInfo.batchItemFailures.length).toBe(1); - } catch (e: any) { - throw e; - } + + const returnedInfo = await certGenInit( + { Records: ["this is an event"] }, + ctx, + () => { + return; + } + ); + expect(returnedInfo.batchItemFailures.length).toBe(1); }); it("should not throw error if code is InvalidParameterValue", async () => { StreamService.getTestResultStream = jest.fn().mockReturnValue([{}]);