Skip to content

Commit

Permalink
feat(cb2-14226): resolve promise
Browse files Browse the repository at this point in the history
  • Loading branch information
naathanbrown committed Oct 3, 2024
1 parent 52a6495 commit 9cd0c7b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
10 changes: 3 additions & 7 deletions src/functions/certGenInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 3 additions & 4 deletions src/services/SQService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
ReceiveMessageCommandOutput,
SQSClient,
SendMessageCommand,
SendMessageCommandInput,
SendMessageCommandOutput,
SendMessageCommandInput
} from "@aws-sdk/client-sqs";

import { Service } from "../models/injector/ServiceDecorator";
Expand Down Expand Up @@ -68,7 +67,7 @@ class SQService {
messageBody: string,
queueName: string,
messageAttributes?: Record<string, MessageAttributeValue>
): Promise<SendMessageCommandOutput | ServiceException> {
) {
// Get the queue URL for the provided queue name
const queueUrlResult: GetQueueUrlCommandOutput = await this.sqsClient.send(
new GetQueueUrlCommand({ QueueName: queueName })
Expand All @@ -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)
);
}
Expand Down
21 changes: 9 additions & 12 deletions tests/unit/certGenInitFunction.unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([{}]);
Expand Down

0 comments on commit 9cd0c7b

Please sign in to comment.