Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
fix: reverts conditional change within getPayload() that broke comp…
Browse files Browse the repository at this point in the history
…atibility with fastify/middie middleware library
  • Loading branch information
didley committed Apr 27, 2024
1 parent 88595a9 commit dcfa8bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/middleware/node/get-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AggregateError from "aggregate-error";
type IncomingMessage = any;

export function getPayload(request: IncomingMessage): Promise<string> {
if ("body" in request) {
if (request.body) {
if (
typeof request.body === "object" &&
"rawBody" in request &&
Expand Down
15 changes: 15 additions & 0 deletions test/integration/get-payload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ describe("getPayload", () => {

expect(await promise).toEqual("foo");
});

it("resolves with a string if the body key of the request is defined but value is undefined", async () => {
const request = new EventEmitter();
// @ts-ignore body is not part of EventEmitter, which we are using
// to mock the request object
request.body = undefined;

const promise = getPayload(request);

// we emit data, to ensure that the body attribute is preferred
request.emit("data", "bar");
request.emit("end");

expect(await promise).toEqual("bar");
});
});

0 comments on commit dcfa8bb

Please sign in to comment.