Aktueller Stand
This commit is contained in:
338
backend/node_modules/@fastify/swagger-ui/test/route.test.js
generated
vendored
338
backend/node_modules/@fastify/swagger-ui/test/route.test.js
generated
vendored
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const nodeTest = require('node:test')
|
||||
const test = nodeTest.test
|
||||
const Fastify = require('fastify')
|
||||
const Swagger = require('@apidevtools/swagger-parser')
|
||||
const yaml = require('yaml')
|
||||
@@ -16,6 +16,7 @@ const {
|
||||
} = require('../examples/options')
|
||||
|
||||
const resolve = require('node:path').resolve
|
||||
const join = require('node:path').join
|
||||
const readFileSync = require('node:fs').readFileSync
|
||||
|
||||
const schemaParamsWithoutDesc = {
|
||||
@@ -71,7 +72,7 @@ test('/documentation/json route', async (t) => {
|
||||
const payload = JSON.parse(res.payload)
|
||||
|
||||
await Swagger.validate(payload)
|
||||
t.pass('valid swagger object')
|
||||
t.assert.ok(true, 'valid swagger object')
|
||||
})
|
||||
|
||||
test('fastify.swagger should return a valid swagger yaml', async (t) => {
|
||||
@@ -94,10 +95,10 @@ test('fastify.swagger should return a valid swagger yaml', async (t) => {
|
||||
url: '/documentation/yaml'
|
||||
})
|
||||
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal(res.headers['content-type'], 'application/x-yaml')
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'application/x-yaml')
|
||||
yaml.parse(res.payload)
|
||||
t.pass('valid swagger yaml')
|
||||
t.assert.ok(true, 'valid swagger yaml')
|
||||
})
|
||||
|
||||
test('/documentation should display index html', async (t) => {
|
||||
@@ -117,10 +118,10 @@ test('/documentation should display index html', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/documentation'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers.location, undefined)
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal('text/html; charset=utf-8', res.headers['content-type'])
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
test('/documentation/ should display index html ', async (t) => {
|
||||
@@ -140,10 +141,10 @@ test('/documentation/ should display index html ', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/documentation/'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers.location, undefined)
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal('text/html; charset=utf-8', res.headers['content-type'])
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
test('/v1/documentation should display index html', async (t) => {
|
||||
@@ -163,10 +164,10 @@ test('/v1/documentation should display index html', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/v1/documentation'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers.location, undefined)
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal('text/html; charset=utf-8', res.headers['content-type'])
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
test('/v1/documentation/ should display index html', async (t) => {
|
||||
@@ -186,17 +187,17 @@ test('/v1/documentation/ should display index html', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/v1/documentation/'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers.location, undefined)
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal('text/html; charset=utf-8', res.headers['content-type'])
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
test('/v1/foobar should display index html', async (t) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.register(async function (fastify, options) {
|
||||
fastify.register(async function (fastify) {
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { routePrefix: '/foobar', noRedirect: true })
|
||||
|
||||
@@ -212,17 +213,17 @@ test('/v1/foobar should display index html', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/v1/foobar'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers.location, undefined)
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal('text/html; charset=utf-8', res.headers['content-type'])
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
test('/v1/foobar/ should display index html', async (t) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.register(async function (fastify, options) {
|
||||
fastify.register(async function (fastify) {
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { routePrefix: '/foobar' })
|
||||
|
||||
@@ -238,10 +239,10 @@ test('/v1/foobar/ should display index html', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/v1/foobar/'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers.location, undefined)
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal('text/html; charset=utf-8', res.headers['content-type'])
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
test('with routePrefix: \'/\' should display index html', async (t) => {
|
||||
@@ -257,10 +258,10 @@ test('with routePrefix: \'/\' should display index html', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers.location, undefined)
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal('text/html; charset=utf-8', res.headers['content-type'])
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
test('/documentation/static/:file should send back the correct file', async (t) => {
|
||||
@@ -284,8 +285,8 @@ test('/documentation/static/:file should send back the correct file', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/index.html'
|
||||
})
|
||||
t.equal(res.statusCode, 302)
|
||||
t.equal(res.headers.location, '/documentation/')
|
||||
t.assert.deepStrictEqual(res.statusCode, 302)
|
||||
t.assert.deepStrictEqual(res.headers.location, '/documentation/')
|
||||
}
|
||||
|
||||
{
|
||||
@@ -293,16 +294,16 @@ test('/documentation/static/:file should send back the correct file', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/'
|
||||
})
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal(res.headers['content-type'], 'text/html; charset=UTF-8')
|
||||
t.equal(
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'text/html; charset=utf-8')
|
||||
t.assert.deepStrictEqual(
|
||||
readFileSync(
|
||||
resolve(__dirname, '..', 'static', 'index.html'),
|
||||
'utf8'
|
||||
),
|
||||
res.payload
|
||||
)
|
||||
t.ok(res.payload.indexOf('swagger-initializer.js') !== -1)
|
||||
t.assert.ok(res.payload.indexOf('swagger-initializer.js') !== -1)
|
||||
}
|
||||
|
||||
{
|
||||
@@ -310,9 +311,9 @@ test('/documentation/static/:file should send back the correct file', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/swagger-initializer.js'
|
||||
})
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal(res.headers['content-type'], 'application/javascript; charset=utf-8')
|
||||
t.ok(res.payload.indexOf('resolveUrl') !== -1)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'application/javascript; charset=utf-8')
|
||||
t.assert.ok(res.payload.indexOf('resolveUrl') !== -1)
|
||||
}
|
||||
|
||||
{
|
||||
@@ -320,9 +321,9 @@ test('/documentation/static/:file should send back the correct file', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/oauth2-redirect.html'
|
||||
})
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal(res.headers['content-type'], 'text/html; charset=UTF-8')
|
||||
t.equal(
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'text/html; charset=utf-8')
|
||||
t.assert.deepStrictEqual(
|
||||
readFileSync(
|
||||
resolve(__dirname, '..', 'static', 'oauth2-redirect.html'),
|
||||
'utf8'
|
||||
@@ -336,9 +337,9 @@ test('/documentation/static/:file should send back the correct file', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/swagger-ui.css'
|
||||
})
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal(res.headers['content-type'], 'text/css; charset=UTF-8')
|
||||
t.equal(
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'text/css; charset=utf-8')
|
||||
t.assert.deepStrictEqual(
|
||||
readFileSync(
|
||||
resolve(__dirname, '..', 'static', 'swagger-ui.css'),
|
||||
'utf8'
|
||||
@@ -352,9 +353,9 @@ test('/documentation/static/:file should send back the correct file', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/swagger-ui-bundle.js'
|
||||
})
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal(res.headers['content-type'], 'application/javascript; charset=UTF-8')
|
||||
t.equal(
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'application/javascript; charset=utf-8')
|
||||
t.assert.deepStrictEqual(
|
||||
readFileSync(
|
||||
resolve(__dirname, '..', 'static', 'swagger-ui-bundle.js'),
|
||||
'utf8'
|
||||
@@ -368,9 +369,9 @@ test('/documentation/static/:file should send back the correct file', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/swagger-ui-standalone-preset.js'
|
||||
})
|
||||
t.equal(typeof res.payload, 'string')
|
||||
t.equal(res.headers['content-type'], 'application/javascript; charset=UTF-8')
|
||||
t.equal(
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'application/javascript; charset=utf-8')
|
||||
t.assert.deepStrictEqual(
|
||||
readFileSync(
|
||||
resolve(__dirname, '..', 'static', 'swagger-ui-standalone-preset.js'),
|
||||
'utf8'
|
||||
@@ -396,8 +397,8 @@ test('/documentation/static/:file should send back file from baseDir', async (t)
|
||||
method: 'GET',
|
||||
url: '/documentation/static/example-logo.svg'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(
|
||||
res.payload,
|
||||
readFileSync(
|
||||
resolve(__dirname, '..', 'examples', 'static', 'example-logo.svg'),
|
||||
@@ -426,9 +427,10 @@ test('/documentation/static/:file 404', async (t) => {
|
||||
url: '/documentation/static/stuff.css'
|
||||
})
|
||||
const payload = JSON.parse(res.payload)
|
||||
t.equal(res.statusCode, 404)
|
||||
t.match(payload, {
|
||||
t.assert.deepStrictEqual(res.statusCode, 404)
|
||||
t.assert.deepStrictEqual(payload, {
|
||||
error: 'Not Found',
|
||||
message: 'Route GET:/documentation/static/stuff.css not found',
|
||||
statusCode: 404
|
||||
})
|
||||
})
|
||||
@@ -455,7 +457,7 @@ test('/documentation2/json route (overwrite)', async (t) => {
|
||||
const payload = JSON.parse(res.payload)
|
||||
|
||||
await Swagger.validate(payload)
|
||||
t.pass('valid swagger object')
|
||||
t.assert.ok(true, 'valid swagger object')
|
||||
})
|
||||
|
||||
test('/documentation/:myfile should return 404 in dynamic mode', async (t) => {
|
||||
@@ -468,13 +470,13 @@ test('/documentation/:myfile should return 404 in dynamic mode', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/documentation/swagger-ui.js'
|
||||
})
|
||||
t.equal(res.statusCode, 404)
|
||||
t.assert.deepStrictEqual(res.statusCode, 404)
|
||||
})
|
||||
|
||||
test('/documentation/:myfile should run custom NotFoundHandler in dynamic mode', async (t) => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
const notFoundHandler = function (req, reply) {
|
||||
const notFoundHandler = function (_req, reply) {
|
||||
reply.code(410).send()
|
||||
}
|
||||
fastify.setNotFoundHandler(notFoundHandler)
|
||||
@@ -485,7 +487,7 @@ test('/documentation/:myfile should run custom NotFoundHandler in dynamic mode',
|
||||
method: 'GET',
|
||||
url: '/documentation/swagger-ui.js'
|
||||
})
|
||||
t.equal(res.statusCode, 410)
|
||||
t.assert.deepStrictEqual(res.statusCode, 410)
|
||||
})
|
||||
|
||||
test('/documentation/* should not return module files when baseDir not set', async (t) => {
|
||||
@@ -498,14 +500,14 @@ test('/documentation/* should not return module files when baseDir not set', asy
|
||||
method: 'GET',
|
||||
url: '/documentation/README.md'
|
||||
})
|
||||
t.equal(res.statusCode, 404)
|
||||
t.assert.deepStrictEqual(res.statusCode, 404)
|
||||
})
|
||||
|
||||
test('should return silent log level of route /documentation', async (t) => {
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.addHook('onRoute', function (route) {
|
||||
t.equal(route.logLevel, 'silent')
|
||||
t.assert.deepStrictEqual(route.logLevel, 'silent')
|
||||
})
|
||||
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
@@ -515,15 +517,15 @@ test('should return silent log level of route /documentation', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/documentation/'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers['content-type'], 'text/html; charset=utf-8')
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'text/html; charset=utf-8')
|
||||
})
|
||||
|
||||
test('should return empty log level of route /documentation', async (t) => {
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.addHook('onRoute', function (route) {
|
||||
t.equal(route.logLevel, '')
|
||||
t.assert.deepStrictEqual(route.logLevel, '')
|
||||
})
|
||||
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
@@ -533,12 +535,39 @@ test('should return empty log level of route /documentation', async (t) => {
|
||||
method: 'GET',
|
||||
url: '/documentation/'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.headers['content-type'], 'text/html; charset=utf-8')
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers['content-type'], 'text/html; charset=utf-8')
|
||||
})
|
||||
|
||||
const assertIndexUrls = (t, indexHtml, prefix) => {
|
||||
t.assert.deepStrictEqual(indexHtml.includes(`href="${prefix}/static/index.css"`), true)
|
||||
t.assert.deepStrictEqual(indexHtml.includes(`src="${prefix}/static/theme/theme-js.js"`), true)
|
||||
t.assert.deepStrictEqual(indexHtml.includes(`href="${prefix}/index.css"`), false)
|
||||
t.assert.deepStrictEqual(indexHtml.includes(`src="${prefix}/theme/theme-js.js"`), false)
|
||||
}
|
||||
|
||||
const validateIndexUrls = async (t, fastify, indexHtml, prefix = '') => {
|
||||
const hrefs = indexHtml.matchAll(/href="([^"]*)"/g)
|
||||
for (const [, path] of hrefs) {
|
||||
const res = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: join(prefix, path)
|
||||
})
|
||||
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
}
|
||||
const srcs = indexHtml.matchAll(/src="([^"]*)"/g)
|
||||
for (const [, path] of srcs) {
|
||||
const res = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: join(prefix, path)
|
||||
})
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
}
|
||||
}
|
||||
|
||||
test('/documentation should display index html with correct asset urls', async (t) => {
|
||||
t.plan(6)
|
||||
t.plan(13)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] } })
|
||||
@@ -547,59 +576,66 @@ test('/documentation should display index html with correct asset urls', async (
|
||||
method: 'GET',
|
||||
url: '/documentation'
|
||||
})
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
|
||||
t.equal(res.payload.includes('href="./documentation/static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./documentation/static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./documentation/index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./documentation/theme/theme-js.js"'), false)
|
||||
|
||||
let cssRes = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/documentation/static/index.css'
|
||||
})
|
||||
t.equal(cssRes.statusCode, 200)
|
||||
cssRes = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: './documentation/static/index.css'
|
||||
})
|
||||
t.equal(cssRes.statusCode, 200)
|
||||
assertIndexUrls(t, res.payload, '/documentation')
|
||||
await validateIndexUrls(t, fastify, res.payload)
|
||||
})
|
||||
|
||||
/**
|
||||
* This emulates when the server is inside an NGINX application that routes by path
|
||||
*/
|
||||
test('/documentation should display index html with correct asset urls when nested', async (t) => {
|
||||
t.plan(5)
|
||||
const testCases = [
|
||||
['/swagger-app', undefined],
|
||||
['/swagger-app/', undefined],
|
||||
['/swagger-app', 'documentation']
|
||||
]
|
||||
testCases.forEach(([prefix, pluginPrefix]) => {
|
||||
test(`${prefix} ${pluginPrefix} should display index html with correct asset urls when nested`, async (t) => {
|
||||
t.plan(13)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(
|
||||
async (childFastify) => {
|
||||
await childFastify.register(fastifySwagger, swaggerOption)
|
||||
await childFastify.register(fastifySwaggerUi, { indexPrefix: prefix, routePrefix: pluginPrefix, theme: { js: [{ filename: 'theme-js.js' }] } })
|
||||
},
|
||||
{
|
||||
prefix: '/swagger-app'
|
||||
}
|
||||
)
|
||||
|
||||
const res = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/swagger-app/documentation'
|
||||
})
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
|
||||
assertIndexUrls(t, res.payload, '/swagger-app/documentation')
|
||||
|
||||
await validateIndexUrls(t, fastify, res.payload)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* This emulates when the server is inside an NGINX application that routes by path
|
||||
*/
|
||||
test('/api/v1/docs should display index html with correct asset urls', async (t) => {
|
||||
t.plan(13)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(
|
||||
async () => {
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] } })
|
||||
},
|
||||
{
|
||||
prefix: '/swagger-app'
|
||||
}
|
||||
)
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { routePrefix: '/api/v1/docs', theme: { js: [{ filename: 'theme-js.js' }] } })
|
||||
|
||||
const res = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/swagger-app/documentation'
|
||||
url: '/api/v1/docs'
|
||||
})
|
||||
|
||||
t.equal(res.payload.includes('href="./documentation/static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./documentation/static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./documentation/index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./documentation/theme/theme-js.js"'), false)
|
||||
|
||||
const cssRes = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/swagger-app/documentation/static/index.css'
|
||||
})
|
||||
t.equal(cssRes.statusCode, 200)
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
assertIndexUrls(t, res.payload, '/api/v1/docs')
|
||||
await validateIndexUrls(t, fastify, res.payload)
|
||||
})
|
||||
|
||||
test('/documentation/ should display index html with correct asset urls', async (t) => {
|
||||
t.plan(4)
|
||||
t.plan(13)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] } })
|
||||
@@ -608,15 +644,14 @@ test('/documentation/ should display index html with correct asset urls', async
|
||||
method: 'GET',
|
||||
url: '/documentation/'
|
||||
})
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
|
||||
t.equal(res.payload.includes('href="./static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./theme/theme-js.js"'), false)
|
||||
assertIndexUrls(t, res.payload, '.')
|
||||
await validateIndexUrls(t, fastify, res.payload, '/documentation/')
|
||||
})
|
||||
|
||||
test('/docs should display index html with correct asset urls when documentation prefix is set', async (t) => {
|
||||
t.plan(4)
|
||||
t.plan(13)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] }, routePrefix: '/docs' })
|
||||
@@ -625,11 +660,10 @@ test('/docs should display index html with correct asset urls when documentation
|
||||
method: 'GET',
|
||||
url: '/docs'
|
||||
})
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
|
||||
t.equal(res.payload.includes('href="./docs/static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./docs/static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./docs/index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./docs/theme/theme-js.js"'), false)
|
||||
assertIndexUrls(t, res.payload, '/docs')
|
||||
await validateIndexUrls(t, fastify, res.payload)
|
||||
})
|
||||
|
||||
test('/docs should display index html with correct asset urls when documentation prefix is set with no leading slash', async (t) => {
|
||||
@@ -643,10 +677,10 @@ test('/docs should display index html with correct asset urls when documentation
|
||||
url: '/docs'
|
||||
})
|
||||
|
||||
t.equal(res.payload.includes('href="docs/static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="docs/static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="docs/index.css"'), false)
|
||||
t.equal(res.payload.includes('src="docs/theme/theme-js.js"'), false)
|
||||
t.assert.strictEqual(res.payload.includes('href="docs/static/index.css"'), true)
|
||||
t.assert.strictEqual(res.payload.includes('src="docs/static/theme/theme-js.js"'), true)
|
||||
t.assert.strictEqual(res.payload.includes('href="docs/index.css"'), false)
|
||||
t.assert.strictEqual(res.payload.includes('src="docs/theme/theme-js.js"'), false)
|
||||
})
|
||||
|
||||
test('/docs/ should display index html with correct asset urls when documentation prefix is set', async (t) => {
|
||||
@@ -660,14 +694,14 @@ test('/docs/ should display index html with correct asset urls when documentatio
|
||||
url: '/docs/'
|
||||
})
|
||||
|
||||
t.equal(res.payload.includes('href="./static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./theme/theme-js.js"'), false)
|
||||
t.assert.strictEqual(res.payload.includes('href="./static/index.css"'), true)
|
||||
t.assert.strictEqual(res.payload.includes('src="./static/theme/theme-js.js"'), true)
|
||||
t.assert.strictEqual(res.payload.includes('href="./index.css"'), false)
|
||||
t.assert.strictEqual(res.payload.includes('src="./theme/theme-js.js"'), false)
|
||||
})
|
||||
|
||||
test('/documentation/ should display index html with correct asset urls', async (t) => {
|
||||
t.plan(4)
|
||||
t.plan(13)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] } })
|
||||
@@ -676,15 +710,15 @@ test('/documentation/ should display index html with correct asset urls', async
|
||||
method: 'GET',
|
||||
url: '/documentation/'
|
||||
})
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
|
||||
t.equal(res.payload.includes('href="./static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./theme/theme-js.js"'), false)
|
||||
assertIndexUrls(t, res.payload, '.')
|
||||
|
||||
await validateIndexUrls(t, fastify, res.payload, '/documentation')
|
||||
})
|
||||
|
||||
test('/docs should display index html with correct asset urls when documentation prefix is set', async (t) => {
|
||||
t.plan(4)
|
||||
t.plan(13)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] }, routePrefix: '/docs' })
|
||||
@@ -693,11 +727,11 @@ test('/docs should display index html with correct asset urls when documentation
|
||||
method: 'GET',
|
||||
url: '/docs'
|
||||
})
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
|
||||
t.equal(res.payload.includes('href="./docs/static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./docs/static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./docs/index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./docs/theme/theme-js.js"'), false)
|
||||
assertIndexUrls(t, res.payload, '/docs')
|
||||
|
||||
await validateIndexUrls(t, fastify, res.payload)
|
||||
})
|
||||
|
||||
test('/docs/ should display index html with correct asset urls when documentation prefix is set', async (t) => {
|
||||
@@ -711,8 +745,26 @@ test('/docs/ should display index html with correct asset urls when documentatio
|
||||
url: '/docs/'
|
||||
})
|
||||
|
||||
t.equal(res.payload.includes('href="./static/index.css"'), true)
|
||||
t.equal(res.payload.includes('src="./static/theme/theme-js.js"'), true)
|
||||
t.equal(res.payload.includes('href="./index.css"'), false)
|
||||
t.equal(res.payload.includes('src="./theme/theme-js.js"'), false)
|
||||
t.assert.strictEqual(res.payload.includes('href="./static/index.css"'), true)
|
||||
t.assert.strictEqual(res.payload.includes('src="./static/theme/theme-js.js"'), true)
|
||||
t.assert.strictEqual(res.payload.includes('href="./index.css"'), false)
|
||||
t.assert.strictEqual(res.payload.includes('src="./theme/theme-js.js"'), false)
|
||||
})
|
||||
|
||||
test('should ignore prefix when register plugin', async (t) => {
|
||||
t.plan(4)
|
||||
const fastify = Fastify()
|
||||
await fastify.register(fastifySwagger, swaggerOption)
|
||||
await fastify.register(fastifySwaggerUi, { routePrefix: '/v1/documentation', prefix: '/' })
|
||||
|
||||
fastify.get('/', () => {})
|
||||
|
||||
const res = await fastify.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/documentation'
|
||||
})
|
||||
t.assert.deepStrictEqual(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.headers.location, undefined)
|
||||
t.assert.deepStrictEqual(typeof res.payload, 'string')
|
||||
t.assert.deepStrictEqual('text/html; charset=utf-8', res.headers['content-type'])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user