Skip to content

Commit bdbfdd5

Browse files
committed
Changes while reviewing
1 parent d88723a commit bdbfdd5

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const checkPatchOverrideSupport = function (req, res) {
3232
* reaching controllers, preventing unhandled errors from unparsed or mis-parsed bodies.
3333
*
3434
* - Skips validation for methods that don't carry bodies (GET, HEAD, OPTIONS, DELETE)
35-
* - Skips validation for endpoints that do not use a body (/release)
35+
* - Skips validation for endpoints that don't carry bodies (/release)
3636
* - Allows text/plain for /search endpoints (which accept plain text search terms)
3737
* - Requires application/json or application/ld+json for all other write endpoints
3838
* - Returns 415 for missing or unsupported Content-Type

routes/__tests__/contentType.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ routeTester.get("/api/info", (req, res) => {
2626
res.status(200).json({ info: true })
2727
})
2828

29+
// DELETE endpoint should pass through without Content-Type validation
30+
routeTester.delete("/api/delete/:_id", (req, res) => {
31+
res.status(200).json({ deleted: req.params._id })
32+
})
33+
34+
// Release endpoint uses PATCH without a JSON body (uses Slug header)
35+
routeTester.patch("/api/release/:_id", (req, res) => {
36+
res.status(200).json({ released: req.params._id })
37+
})
38+
2939
// Error handler matching the app's pattern
3040
routeTester.use(rest.messenger)
3141

@@ -118,4 +128,18 @@ describe("Content-Type validation middleware", () => {
118128
expect(response.body.info).toBe(true)
119129
})
120130

131+
it("skips validation for DELETE requests", async () => {
132+
const response = await request(routeTester)
133+
.delete("/api/delete/abc123")
134+
expect(response.statusCode).toBe(200)
135+
expect(response.body.deleted).toBe("abc123")
136+
})
137+
138+
it("skips validation for PATCH on release endpoint", async () => {
139+
const response = await request(routeTester)
140+
.patch("/api/release/abc123")
141+
expect(response.statusCode).toBe(200)
142+
expect(response.body.released).toBe("abc123")
143+
})
144+
121145
})

0 commit comments

Comments
 (0)