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
37 changes: 35 additions & 2 deletions packages/inertia/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,40 @@ describe('inertia', () => {
expect(body.url).toBe('/users')
})

it('overrides page.url via options.url on a non-GET request', async () => {
it('falls back to c.req.url when Referer is unparseable on non-GET requests', async () => {
const app = new Hono()
app.use(inertia({ version: 'v1' }))
app.post('/users', (c) => c.render('Users/New'))

const res = await app.request('/users', {
method: 'POST',
headers: {
'X-Inertia': 'true',
'X-Inertia-Version': 'v1',
Referer: 'invalid-url',
},
})

const body = (await res.json()) as PageObject
expect(body.url).toBe('/users')
})

it('falls back to c.req.url when options.url is unparseable on non-GET requests', async () => {
const app = new Hono()
app.use(inertia({ version: 'v1' }))
// '#' is unusable as a URL because it's just a URI fragment
app.post('/users', (c) => c.render('Users/New', {}, { url: '#' }))

const res = await app.request('/users', {
method: 'POST',
headers: { 'X-Inertia': 'true', 'X-Inertia-Version': 'v1' },
})

const body = (await res.json()) as PageObject
expect(body.url).toBe('/users')
})

it('overrides page.url via options.url on non-GET requests', async () => {
const app = new Hono()
app.use(inertia({ version: 'v1' }))
app.post('/users', (c) => c.render('Users/New', {}, { url: '/users/new' }))
Expand All @@ -258,7 +291,7 @@ describe('inertia', () => {
expect(body.url).toBe('/users/new')
})

it('prefers options.url over Referer when both are present on a non-GET request', async () => {
it('prefers options.url over Referer when both are present on non-GET requests', async () => {
const app = new Hono()
app.use(inertia({ version: 'v1' }))
app.post('/users', (c) => c.render('Users/New', {}, { url: '/override' }))
Expand Down
Loading