diff --git a/package.json b/package.json index 25ec437..7f0ae37 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "license": "MIT", "devDependencies": { "@types/node": "^22.0.0", - "fastify": "^4.6.0", + "fastify": "^5.2.1", "husky": "^9.0.11", "proxyquire": "^2.1.3", "snazzy": "^9.0.0", diff --git a/test/index.test.js b/test/index.test.js index 22aa27c..afecabe 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -10,54 +10,61 @@ const test = tap.test tap.plan(15) -test('Should allow custom AJV instance for querystring', async t => { - t.plan(1) - const customAjv = new AJV({ coerceTypes: false }) - const server = Fastify() +test( + 'Should allow custom AJV instance for querystring', + { only: true }, + async t => { + t.plan(1) + const customAjv = new AJV({ coerceTypes: false }) + const server = Fastify() - server.register(plugin, {}) + server.register(plugin, {}) - server.get( - '/', - { - schema: { - querystring: { - msg: { - type: 'array', - items: { - type: 'string' + server.get( + '/', + { + schema: { + querystring: { + type: 'object', + properties: { + msg: { + type: 'array', + items: { + type: 'string' + } + } } } + }, + config: { + schemaValidators: { + // TODO: normalize to query + querystring: customAjv + } } }, - config: { - schemaValidators: { - // TODO: normalize to query - querystring: customAjv - } - } - }, - (req, reply) => {} - ) + (req, reply) => {} + ) - try { - const res = await server.inject({ - method: 'GET', - url: '/', - query: { - msg: ['hello world'] - } - }) + try { + const res = await server.inject({ + method: 'GET', + url: '/', + query: { + msg: ['hello world'] + } + }) - t.equal( - res.statusCode, - 400, - 'Should coerce the single element array into string' - ) - } catch (err) { - t.error(err) + t.equal( + res.statusCode, + 400, + 'Should coerce the single element array into string' + ) + } catch (err) { + t.error(err) + } } -}) +) test('Should allow custom AJV instance for body', async t => { t.plan(2) @@ -125,8 +132,11 @@ test('Should allow custom AJV instance for params', async t => { { schema: { params: { - msg: { - type: 'integer' + type: 'object', + properties: { + msg: { + type: 'integer' + } } } }, @@ -170,8 +180,11 @@ test('Should allow custom AJV instance for headers', async t => { { schema: { headers: { - 'x-type': { - type: 'integer' + type: 'object', + properties: { + 'x-type': { + type: 'integer' + } } } }, @@ -234,8 +247,11 @@ test('Should work with referenced schemas (querystring)', async t => { { schema: { query: { - msg: { - $ref: 'some#' + type: 'object', + properties: { + msg: { + $ref: 'some#' + } } } }, @@ -289,8 +305,11 @@ test('Should work with referenced schemas (params)', async t => { { schema: { params: { - id: { - $ref: 'some#' + type: 'object', + properties: { + id: { + $ref: 'some#' + } } } }, @@ -337,8 +356,11 @@ test('Should work with referenced schemas (headers)', async t => { { schema: { headers: { - 'x-id': { - $ref: 'some#' + type: 'object', + properties: { + 'x-id': { + $ref: 'some#' + } } } }, @@ -577,13 +599,19 @@ test('Should work with parent nested schemas', async t => { { schema: { querystring: { - msg: { - $ref: 'some#' + type: 'object', + properties: { + msg: { + $ref: 'some#' + } } }, headers: { - 'x-another': { - $ref: 'another#' + type: 'object', + properties: { + 'x-another': { + $ref: 'another#' + } } } }, @@ -659,13 +687,19 @@ test('Should handle parsing to querystring (query)', async t => { { schema: { query: { - msg: { - $ref: 'some#' + type: 'object', + properties: { + msg: { + $ref: 'some#' + } } }, headers: { - 'x-another': { - $ref: 'another#' + type: 'object', + properties: { + 'x-another': { + $ref: 'another#' + } } } }, @@ -756,13 +790,19 @@ test('Should use default plugin validator as fallback', async t => { { schema: { query: { - msg: { - $ref: 'some#' + type: 'object', + properties: { + msg: { + $ref: 'some#' + } } }, headers: { - 'x-another': { - $ref: 'another#' + type: 'object', + properties: { + 'x-another': { + $ref: 'another#' + } } } } @@ -830,7 +870,7 @@ test('Should always cache schema to default plugin validator', async t => { } }) - server.register(async (instance, opts, done) => { + server.register(async (instance, opts) => { instance.addSchema({ $id: 'another', type: 'integer' @@ -843,13 +883,19 @@ test('Should always cache schema to default plugin validator', async t => { { schema: { query: { - msg: { - $ref: 'some#' + type: 'object', + properties: { + msg: { + $ref: 'some#' + } } }, headers: { - 'x-another': { - $ref: 'another#' + type: 'object', + properties: { + 'x-another': { + $ref: 'another#' + } } } }, @@ -922,13 +968,19 @@ test('Should use default provided validator as fallback', async t => { { schema: { query: { - msg: { - $ref: 'some#' + type: 'object', + properties: { + msg: { + $ref: 'some#' + } } }, headers: { - 'x-another': { - $ref: 'another#' + type: 'object', + properties: { + 'x-another': { + $ref: 'another#' + } } } }