Skip to content

Commit

Permalink
test: ensure no regression
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Dec 17, 2023
1 parent f731a99 commit 70183fc
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/preflight.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,76 @@ test('Can override preflight response with preflightContinue', t => {
})
})
})

test('Should support ongoing prefix ', t => {
t.plan(12)

const fastify = Fastify()

fastify.register(async (instance) => {
instance.register(cors)
}, { prefix: '/prefix' })

// support prefixed route
fastify.inject({
method: 'OPTIONS',
url: '/prefix',
headers: {
'access-control-request-method': 'GET',
origin: 'example.com'
}
}, (err, res) => {
t.error(err)
delete res.headers.date
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.match(res.headers, {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
vary: 'Origin, Access-Control-Request-Headers',
'content-length': '0'
})
})

// support prefixed route without / continue
fastify.inject({
method: 'OPTIONS',
url: '/prefixfoo',
headers: {
'access-control-request-method': 'GET',
origin: 'example.com'
}
}, (err, res) => {
t.error(err)
delete res.headers.date
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.match(res.headers, {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
vary: 'Origin, Access-Control-Request-Headers',
'content-length': '0'
})
})

// support prefixed route with / continue
fastify.inject({
method: 'OPTIONS',
url: '/prefix/foo',
headers: {
'access-control-request-method': 'GET',
origin: 'example.com'
}
}, (err, res) => {
t.error(err)
delete res.headers.date
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.match(res.headers, {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
vary: 'Origin, Access-Control-Request-Headers',
'content-length': '0'
})
})
})

0 comments on commit 70183fc

Please sign in to comment.