Skip to content

Commit 34a4840

Browse files
authored
Merge pull request #90 from jaredwray/fix-delete-endpoing-allows-string,-JSON,-or-any
fix: delete endpoing allows string, JSON, or any
2 parents 431b558 + 64c3912 commit 34a4840

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jaredwray/mockhttp",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Mock Http - Easy way to mock http with httpbin replacement",
55
"type": "module",
66
"main": "dist/index.js",

src/routes/http-methods/delete.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ import type { FastifyInstance, FastifyRequest, FastifySchema } from "fastify";
33
const deleteSchema: FastifySchema = {
44
description: "Handles a DELETE request and returns request information",
55
tags: ["HTTP Methods"],
6-
body: {
7-
oneOf: [
8-
{
9-
type: "object",
10-
additionalProperties: true,
11-
description: "JSON body of the DELETE request",
12-
},
13-
{
14-
type: "string",
15-
description: "String body of the DELETE request",
16-
},
17-
],
18-
},
196
response: {
207
200: {
218
type: "object",
@@ -26,10 +13,11 @@ const deleteSchema: FastifySchema = {
2613
oneOf: [
2714
{ type: "object", additionalProperties: true },
2815
{ type: "string" },
16+
{ type: "null" },
2917
],
3018
},
3119
},
32-
required: ["method", "headers", "body"],
20+
required: ["method", "headers"],
3321
},
3422
},
3523
};

test/routes/http-methods/delete.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,17 @@ describe("DELETE /delete", () => {
8383
expect(responseBody.headers["content-type"]).toBe("text/plain");
8484
expect(responseBody.body).toBe("This is a plain text body");
8585
});
86+
87+
it("should handle no body", async () => {
88+
const response = await fastify.inject({
89+
method: "DELETE",
90+
url: "/delete",
91+
});
92+
93+
expect(response.statusCode).toBe(200);
94+
95+
const responseBody = response.json();
96+
expect(responseBody.method).toBe("DELETE");
97+
expect(responseBody.body).toBeUndefined();
98+
});
8699
});

0 commit comments

Comments
 (0)