Skip to content

Commit

Permalink
fix: do not call next() twice (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexforsyth authored Nov 13, 2020
1 parent eee41e8 commit 0964faf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions packages/middleware-sdk-sqs/src/receive-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
16 changes: 16 additions & 0 deletions packages/middleware-sdk-sqs/src/receive-messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 0964faf

Please sign in to comment.