From 0964faf99bd854cde98f995f6e431d6c7178f427 Mon Sep 17 00:00:00 2001 From: Alexander Forsyth Date: Fri, 13 Nov 2020 12:47:47 -0500 Subject: [PATCH] fix: do not call next() twice (#1680) --- .../middleware-sdk-sqs/src/receive-message.ts | 4 +--- .../src/receive-messages.spec.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/middleware-sdk-sqs/src/receive-message.ts b/packages/middleware-sdk-sqs/src/receive-message.ts index a84801878c04..aeb4dad9ceb6 100644 --- a/packages/middleware-sdk-sqs/src/receive-message.ts +++ b/packages/middleware-sdk-sqs/src/receive-message.ts @@ -44,9 +44,7 @@ export function receiveMessageMiddleware(options: PreviouslyResolved): Initializ throw new Error("Invalid MD5 checksum on messages: " + messageIds.join(", ")); } - return next({ - ...args, - }); + return resp; }; } diff --git a/packages/middleware-sdk-sqs/src/receive-messages.spec.ts b/packages/middleware-sdk-sqs/src/receive-messages.spec.ts index 2fc7c1b95f71..ae4c6ef765d9 100644 --- a/packages/middleware-sdk-sqs/src/receive-messages.spec.ts +++ b/packages/middleware-sdk-sqs/src/receive-messages.spec.ts @@ -14,6 +14,22 @@ describe("receiveMessageMiddleware", () => { mockHashDigest.mockClear(); }); + it("should only call next once", async () => { + const next = jest.fn().mockReturnValue({ + output: { + Messages: [ + { Body: "foo", MD5OfBody: "00", MessageId: "fooMessage" }, + { Body: "bar", MD5OfBody: "00", MessageId: "barMessage" }, + ], + }, + }); + const handler = receiveMessageMiddleware({ + md5: MockHash, + })(next, {} as any); + await handler({ input: {} }); + expect(next).toBeCalledTimes(1); + }); + it("should do nothing if the checksums match", async () => { const next = jest.fn().mockReturnValue({ output: {