Skip to content

Commit 0964faf

Browse files
authored
fix: do not call next() twice (#1680)
1 parent eee41e8 commit 0964faf

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/middleware-sdk-sqs/src/receive-message.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export function receiveMessageMiddleware(options: PreviouslyResolved): Initializ
4444
throw new Error("Invalid MD5 checksum on messages: " + messageIds.join(", "));
4545
}
4646

47-
return next({
48-
...args,
49-
});
47+
return resp;
5048
};
5149
}
5250

packages/middleware-sdk-sqs/src/receive-messages.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ describe("receiveMessageMiddleware", () => {
1414
mockHashDigest.mockClear();
1515
});
1616

17+
it("should only call next once", async () => {
18+
const next = jest.fn().mockReturnValue({
19+
output: {
20+
Messages: [
21+
{ Body: "foo", MD5OfBody: "00", MessageId: "fooMessage" },
22+
{ Body: "bar", MD5OfBody: "00", MessageId: "barMessage" },
23+
],
24+
},
25+
});
26+
const handler = receiveMessageMiddleware({
27+
md5: MockHash,
28+
})(next, {} as any);
29+
await handler({ input: {} });
30+
expect(next).toBeCalledTimes(1);
31+
});
32+
1733
it("should do nothing if the checksums match", async () => {
1834
const next = jest.fn().mockReturnValue({
1935
output: {

0 commit comments

Comments
 (0)