Skip to content

Commit

Permalink
fix: do not call next() twice
Browse files Browse the repository at this point in the history
  • Loading branch information
alexforsyth committed Nov 13, 2020
1 parent a3fab9f commit 58e4d4a
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
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
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 58e4d4a

Please sign in to comment.