Aktueller Stand
This commit is contained in:
327
backend/node_modules/fastify/test/route-prefix.test.js
generated
vendored
327
backend/node_modules/fastify/test/route-prefix.test.js
generated
vendored
@@ -1,10 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const Fastify = require('..')
|
||||
const { waitForCb } = require('./toolkit')
|
||||
|
||||
test('Prefix options should add a prefix for all the routes inside a register / 1', t => {
|
||||
test('Prefix options should add a prefix for all the routes inside a register / 1', (t, testDone) => {
|
||||
t.plan(6)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -27,32 +27,37 @@ test('Prefix options should add a prefix for all the routes inside a register /
|
||||
done()
|
||||
}, { prefix: '/v1' })
|
||||
|
||||
const completion = waitForCb({ steps: 3 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/first'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/first' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/first' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/first'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v1/first' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/first' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/v2/first'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v1/v2/first' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/v2/first' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('Prefix options should add a prefix for all the routes inside a register / 2', t => {
|
||||
test('Prefix options should add a prefix for all the routes inside a register / 2', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -67,24 +72,27 @@ test('Prefix options should add a prefix for all the routes inside a register /
|
||||
done()
|
||||
}, { prefix: '/v1' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/first'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v1/first' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/first' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/second'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v1/second' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/second' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('Prefix options should add a prefix for all the chained routes inside a register / 3', t => {
|
||||
test('Prefix options should add a prefix for all the chained routes inside a register / 3', (t, testDone) => {
|
||||
t.plan(4)
|
||||
|
||||
const fastify = Fastify()
|
||||
@@ -100,24 +108,27 @@ test('Prefix options should add a prefix for all the chained routes inside a reg
|
||||
done()
|
||||
}, { prefix: '/v1' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/first'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v1/first' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/first' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/second'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v1/second' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/second' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('Prefix should support parameters as well', t => {
|
||||
test('Prefix should support parameters as well', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -132,12 +143,13 @@ test('Prefix should support parameters as well', t => {
|
||||
method: 'GET',
|
||||
url: '/v1/param/hello'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { id: 'param' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { id: 'param' })
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('Prefix should support /', t => {
|
||||
test('Prefix should support /', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -152,12 +164,13 @@ test('Prefix should support /', t => {
|
||||
method: 'GET',
|
||||
url: '/v1'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('Prefix without /', t => {
|
||||
test('Prefix without /', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -172,12 +185,13 @@ test('Prefix without /', t => {
|
||||
method: 'GET',
|
||||
url: '/v1'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('Prefix with trailing /', t => {
|
||||
test('Prefix with trailing /', (t, testDone) => {
|
||||
t.plan(6)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -199,32 +213,35 @@ test('Prefix with trailing /', t => {
|
||||
done()
|
||||
}, { prefix: '/v1/' })
|
||||
|
||||
const completion = waitForCb({ steps: 3 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/route1'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world1' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world1' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/route2'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world2' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world2' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/inner/route3'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world3' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world3' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('Prefix works multiple levels deep', t => {
|
||||
test('Prefix works multiple levels deep', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -248,12 +265,13 @@ test('Prefix works multiple levels deep', t => {
|
||||
method: 'GET',
|
||||
url: '/v1/v2/v3'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('Different register - encapsulation check', t => {
|
||||
test('Different register - encapsulation check', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -281,24 +299,27 @@ test('Different register - encapsulation check', t => {
|
||||
done()
|
||||
}, { prefix: '/v3' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/v2'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v1/v2' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/v2' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v3/v4'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { route: '/v3/v4' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v3/v4' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('Can retrieve prefix within encapsulated instances', t => {
|
||||
test('Can retrieve prefix within encapsulated instances', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -317,24 +338,27 @@ test('Can retrieve prefix within encapsulated instances', t => {
|
||||
done()
|
||||
}, { prefix: '/v1' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/one'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.payload, '/v1')
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(res.payload, '/v1')
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/v2/two'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.payload, '/v1/v2')
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(res.payload, '/v1/v2')
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -346,24 +370,27 @@ test('matches both /prefix and /prefix/ with a / route', t => {
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('prefix "/prefix/" does not match "/prefix" with a / route', t => {
|
||||
test('prefix "/prefix/" does not match "/prefix" with a / route', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -375,24 +402,27 @@ test('prefix "/prefix/" does not match "/prefix" with a / route', t => {
|
||||
done()
|
||||
}, { prefix: '/prefix/' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 404)
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(res.statusCode, 404)
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: true
|
||||
@@ -406,24 +436,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes: true', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes: true', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreDuplicateSlashes: true
|
||||
@@ -437,24 +470,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes:
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: false', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: false', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: false
|
||||
@@ -473,24 +509,27 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: false', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: false', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreDuplicateSlashes: false
|
||||
@@ -509,24 +548,27 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: true,
|
||||
@@ -541,24 +583,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: false', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: false', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: true,
|
||||
@@ -573,24 +618,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "both" (default), ignoreTrailingSlash: true', t => {
|
||||
test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "both" (default), ignoreTrailingSlash: true', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: true
|
||||
@@ -612,16 +660,17 @@ test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "
|
||||
method: 'GET',
|
||||
url: '/prefix//'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), {
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
||||
error: 'Not Found',
|
||||
message: 'Route GET:/prefix// not found',
|
||||
statusCode: 404
|
||||
})
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify({
|
||||
ignoreDuplicateSlashes: true
|
||||
@@ -643,12 +692,13 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
||||
method: 'GET',
|
||||
url: '/prefix//'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: true,
|
||||
@@ -671,12 +721,13 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
||||
method: 'GET',
|
||||
url: '/prefix//'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', t => {
|
||||
test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
|
||||
t.plan(2)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: true,
|
||||
@@ -699,12 +750,13 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
|
||||
method: 'GET',
|
||||
url: '/prefix//'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
testDone()
|
||||
})
|
||||
})
|
||||
|
||||
test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreTrailingSlash: false', t => {
|
||||
test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreTrailingSlash: false', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: false
|
||||
@@ -723,24 +775,27 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(JSON.parse(res.payload).statusCode, 404)
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload).statusCode, 404)
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreDuplicateSlashes: false', t => {
|
||||
test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreDuplicateSlashes: false', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreDuplicateSlashes: false
|
||||
@@ -759,24 +814,27 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(JSON.parse(res.payload).statusCode, 404)
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload).statusCode, 404)
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", ignoreTrailingSlash: false', t => {
|
||||
test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", ignoreTrailingSlash: false', (t, testDone) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify({
|
||||
ignoreTrailingSlash: false
|
||||
@@ -795,21 +853,24 @@ test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", igno
|
||||
done()
|
||||
}, { prefix: '/prefix' })
|
||||
|
||||
const completion = waitForCb({ steps: 2 })
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix/'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.same(JSON.parse(res.payload), { hello: 'world' })
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
|
||||
completion.stepIn()
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/prefix'
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(JSON.parse(res.payload).statusCode, 404)
|
||||
t.assert.ifError(err)
|
||||
t.assert.deepStrictEqual(JSON.parse(res.payload).statusCode, 404)
|
||||
completion.stepIn()
|
||||
})
|
||||
completion.patience.then(testDone)
|
||||
})
|
||||
|
||||
test('calls onRoute only once when prefixing', async t => {
|
||||
@@ -839,5 +900,5 @@ test('calls onRoute only once when prefixing', async t => {
|
||||
|
||||
await fastify.ready()
|
||||
|
||||
t.same(onRouteCalled, 1)
|
||||
t.assert.deepStrictEqual(onRouteCalled, 1)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user