Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/middleware/method-override/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ describe('Method Override Middleware', () => {
queryValue: c.req.query('_method') ?? null,
})
})
app.on(['post', 'delete'], '/posts/details', async (c) => {
return c.json({
method: c.req.method,
page: c.req.query('page') ?? null,
queryValue: c.req.query('_method') ?? null,
})
})

it('Should override POST to DELETE', async () => {
const res = await app.request('/posts?_method=delete', {
Expand All @@ -185,6 +192,18 @@ describe('Method Override Middleware', () => {
})
})

it('Should preserve other query parameters when overriding method', async () => {
const res = await app.request('/posts/details?_method=delete&page=2', {
method: 'POST',
})
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
method: 'DELETE',
page: '2',
queryValue: null,
})
})

it('Should not override GET request', async () => {
const res = await app.request('/posts?_method=delete', {
method: 'GET',
Expand Down