diff --git a/test/auth.test.js b/test/auth.test.js index 5cefb82..d0d63b5 100644 --- a/test/auth.test.js +++ b/test/auth.test.js @@ -24,7 +24,7 @@ test('Clean status code through auth pipeline', (t, done) => { app.register(fastifyAuth) .after(() => { app.addHook('preHandler', app.auth([failWithCode('one', 501), failWithCode('two', 502)])) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) }) app.inject({ @@ -51,7 +51,7 @@ test('defaultRelation: used when relation not specified', async (t) => { method: 'GET', url: '/welcome', preHandler: app.auth([successWithCode('one', 200), failWithCode('two', 502)]), - handler: async (req, reply) => { + handler: async (_req, reply) => { console.log('fawzihandler1') await reply.send({ hello: 'welcome' }) } @@ -61,7 +61,7 @@ test('defaultRelation: used when relation not specified', async (t) => { method: 'GET', url: '/bye', preHandler: app.auth([failWithCode('one', 503), successWithCode('two', 200)], { relation: 'or' }), - handler: (req, reply) => { + handler: (_req, reply) => { reply.send({ hello: 'bye' }) } }) @@ -89,7 +89,7 @@ test('Options: non-array functions input', (t, done) => { app.register(fastifyAuth).after(() => { try { app.addHook('preHandler', app.auth('bogus')) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) } catch (error) { t.assert.ok(error) t.assert.strictEqual(error.message, 'You must give an array of functions to the auth function') @@ -113,7 +113,7 @@ test('Options: empty array functions input', (t, done) => { app.register(fastifyAuth).after(() => { try { app.addHook('preHandler', app.auth([])) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) } catch (error) { t.assert.ok(error) t.assert.strictEqual(error.message, 'Missing auth functions') @@ -137,7 +137,7 @@ test('Options: faulty relation', (t, done) => { app.register(fastifyAuth).after(() => { try { app.addHook('preHandler', app.auth([successWithCode('one', 201)], { relation: 'foo' })) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) } catch (error) { t.assert.ok(error) t.assert.strictEqual(error.message, 'The value of options.relation should be one of [\'or\', \'and\']') @@ -161,7 +161,7 @@ test('Options: faulty run', (t, done) => { app.register(fastifyAuth).after(() => { try { app.addHook('preHandler', app.auth([successWithCode('one', 201)], { run: 'foo' })) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) } catch (error) { t.assert.ok(error) t.assert.strictEqual(error.message, 'The value of options.run must be \'all\'') @@ -185,7 +185,7 @@ test('Avoid status code overwriting', (t, done) => { app.register(fastifyAuth) .after(() => { app.addHook('preHandler', app.auth([successWithCode('one', 201), successWithCode('two', 202)])) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) }) app.inject({ @@ -209,7 +209,7 @@ test('Last win when all failures', (t, done) => { app.register(fastifyAuth) .after(() => { app.addHook('preHandler', app.auth([failWithCode('one', 501), failWithCode('two', 502)])) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) }) app.inject({ @@ -232,7 +232,7 @@ test('First success win', (t, done) => { app.register(fastifyAuth) .after(() => { app.addHook('preHandler', app.auth([successWithCode('one', 201), successWithCode('two', 202)])) - app.get('/', (req, res) => res.send(42)) + app.get('/', (_req, res) => res.send(42)) }) app.inject({ diff --git a/test/example-async.js b/test/example-async.js index 192d8d6..b96bd6c 100644 --- a/test/example-async.js +++ b/test/example-async.js @@ -17,7 +17,7 @@ function build (opts) { const jwt = this.jwt const level = this.level['authdb-async'] - if (request.body && request.body.failureWithReply) { + if (request.body?.failureWithReply) { reply.code(401).send({ error: 'Unauthorized' }) return Promise.reject(new Error()) } @@ -44,7 +44,7 @@ function build (opts) { }) } - function verifyUserAndPassword (request, reply, done) { + function verifyUserAndPassword (request, _reply, done) { const level = this.level['authdb-async'] level.get(request.body.user, onUser) diff --git a/test/example-composited.js b/test/example-composited.js index 6d3163c..adf8249 100644 --- a/test/example-composited.js +++ b/test/example-composited.js @@ -15,7 +15,7 @@ function build (opts) { fastify.decorate('verifyOddAsync', verifyOddAsync) fastify.decorate('verifyBigAsync', verifyBigAsync) - function verifyNumber (request, reply, done) { + function verifyNumber (request, _reply, done) { const n = request.body.n if (typeof (n) !== 'number') { @@ -27,7 +27,7 @@ function build (opts) { return done() } - function verifyOdd (request, reply, done) { + function verifyOdd (request, _reply, done) { const n = request.body.n if (typeof (n) !== 'number' || n % 2 === 0) { @@ -39,7 +39,7 @@ function build (opts) { return done() } - function verifyBig (request, reply, done) { + function verifyBig (request, _reply, done) { const n = request.body.n if (typeof (n) !== 'number' || n < 100) { @@ -75,7 +75,7 @@ function build (opts) { fastify.route({ method: 'GET', url: '/', - handler: (req, reply) => { + handler: (_req, reply) => { reply.send({ hello: 'world' }) } }) diff --git a/test/example-composited.test.js b/test/example-composited.test.js index 017a871..02b5aa6 100644 --- a/test/example-composited.test.js +++ b/test/example-composited.test.js @@ -660,13 +660,13 @@ test('Check run all line fail with AND', (t, done) => { method: 'GET', url: '/run-all-pipe', preHandler: fastify.auth([ - (request, reply, done) => { t.assert.ok('executed 1'); done() }, - (request, reply, done) => { t.assert.ok('executed 2'); done(new Error('second')) }, - (request, reply, done) => { t.assert.ok('executed 3'); done() }, - (request, reply, done) => { t.assert.ok('executed 4'); done() }, - (request, reply, done) => { t.assert.ok('executed 5'); done(new Error('fifth')) } + (_request, _reply, done) => { t.assert.ok('executed 1'); done() }, + (_request, _reply, done) => { t.assert.ok('executed 2'); done(new Error('second')) }, + (_request, _reply, done) => { t.assert.ok('executed 3'); done() }, + (_request, _reply, done) => { t.assert.ok('executed 4'); done() }, + (_request, _reply, done) => { t.assert.ok('executed 5'); done(new Error('fifth')) } ], { relation: 'and', run: 'all' }), - handler: (req, reply) => { reply.send({ hello: 'world' }) } + handler: (_req, reply) => { reply.send({ hello: 'world' }) } }) }) @@ -693,13 +693,13 @@ test('Check run all line with AND', (t, done) => { method: 'GET', url: '/run-all-pipe', preHandler: fastify.auth([ - (request, reply, done) => { t.assert.ok('executed 1'); done() }, - (request, reply, done) => { t.assert.ok('executed 2'); done() }, - (request, reply, done) => { t.assert.ok('executed 3'); done() }, - (request, reply, done) => { t.assert.ok('executed 4'); done() }, - (request, reply, done) => { t.assert.ok('executed 5'); done() } + (_request, _reply, done) => { t.assert.ok('executed 1'); done() }, + (_request, _reply, done) => { t.assert.ok('executed 2'); done() }, + (_request, _reply, done) => { t.assert.ok('executed 3'); done() }, + (_request, _reply, done) => { t.assert.ok('executed 4'); done() }, + (_request, _reply, done) => { t.assert.ok('executed 5'); done() } ], { relation: 'and', run: 'all' }), - handler: (req, reply) => { reply.send({ hello: 'world' }) } + handler: (_req, reply) => { reply.send({ hello: 'world' }) } }) }) @@ -722,13 +722,13 @@ test('Check run all line with OR', (t, done) => { method: 'GET', url: '/run-all-pipe', preHandler: fastify.auth([ - (req, reply, done) => { t.assert.ok('executed 1'); done(new Error('primo')) }, - (req, reply, done) => { t.assert.ok('executed 2'); done(new Error('secondo')) }, - (req, reply, done) => { t.assert.ok('executed 3'); done() }, - (req, reply, done) => { t.assert.ok('executed 4'); done(new Error('quarto')) }, - (req, reply, done) => { t.assert.ok('executed 5'); done() } + (_req, _reply, done) => { t.assert.ok('executed 1'); done(new Error('primo')) }, + (_req, _reply, done) => { t.assert.ok('executed 2'); done(new Error('secondo')) }, + (_req, _reply, done) => { t.assert.ok('executed 3'); done() }, + (_req, _reply, done) => { t.assert.ok('executed 4'); done(new Error('quarto')) }, + (_req, _reply, done) => { t.assert.ok('executed 5'); done() } ], { relation: 'or', run: 'all' }), - handler: (req, reply) => { reply.send({ hello: 'world' }) } + handler: (_req, reply) => { reply.send({ hello: 'world' }) } }) }) @@ -751,13 +751,13 @@ test('Check run all fail line with OR', (t, done) => { method: 'GET', url: '/run-all-pipe', preHandler: fastify.auth([ - (req, reply, done) => { t.assert.ok('executed 1'); done(new Error('primo')) }, - (req, reply, done) => { t.assert.ok('executed 2'); done(new Error('secondo')) }, - (req, reply, done) => { t.assert.ok('executed 3'); done(new Error('terzo')) }, - (req, reply, done) => { t.assert.ok('executed 4'); done(new Error('quarto')) }, - (req, reply, done) => { t.assert.ok('executed 5'); done(new Error('quinto')) } + (_req, _reply, done) => { t.assert.ok('executed 1'); done(new Error('primo')) }, + (_req, _reply, done) => { t.assert.ok('executed 2'); done(new Error('secondo')) }, + (_req, _reply, done) => { t.assert.ok('executed 3'); done(new Error('terzo')) }, + (_req, _reply, done) => { t.assert.ok('executed 4'); done(new Error('quarto')) }, + (_req, _reply, done) => { t.assert.ok('executed 5'); done(new Error('quinto')) } ], { relation: 'or', run: 'all' }), - handler: (req, reply) => { reply.send({ hello: 'world' }) } + handler: (_req, reply) => { reply.send({ hello: 'world' }) } }) }) @@ -784,10 +784,10 @@ test('Ignore last status', (t, done) => { method: 'GET', url: '/run-all-status', preHandler: fastify.auth([ - (req, reply, done) => { t.assert.ok('executed 1'); done() }, - (req, reply, done) => { t.assert.ok('executed 2'); done(new Error('last')) } + (_req, _reply, done) => { t.assert.ok('executed 1'); done() }, + (_req, _reply, done) => { t.assert.ok('executed 2'); done(new Error('last')) } ], { relation: 'or', run: 'all' }), - handler: (req, reply) => { reply.send({ hello: 'world' }) } + handler: (_req, reply) => { reply.send({ hello: 'world' }) } }) }) @@ -883,10 +883,10 @@ test('Clean status code settle by user', (t, done) => { method: 'GET', url: '/run-all-status', preHandler: fastify.auth([ - (req, reply, done) => { t.assert.ok('executed 1'); done() }, - (req, reply, done) => { t.assert.ok('executed 2'); reply.code(400); done(new Error('last')) } + (_req, _reply, done) => { t.assert.ok('executed 1'); done() }, + (_req, reply, done) => { t.assert.ok('executed 2'); reply.code(400); done(new Error('last')) } ], { relation: 'or', run: 'all' }), - handler: (req, reply) => { reply.send({ hello: 'world' }) } + handler: (_req, reply) => { reply.send({ hello: 'world' }) } }) }) diff --git a/test/example.js b/test/example.js index 7bc50cf..cbd4d97 100644 --- a/test/example.js +++ b/test/example.js @@ -71,7 +71,7 @@ function build (opts) { } } - function verifyUserAndPassword (request, reply, done) { + function verifyUserAndPassword (request, _reply, done) { const level = this.level.authdb if (!request.body || !request.body.user) { diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 0a531aa..44c44be 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -31,14 +31,14 @@ app.register(fastifyAuth).after((_err) => { }, ]) app.auth([ - function (request, reply, done) { + function () { expectType(this) }, ]) - const auth = app.auth([(request, reply, done) => {}]) + const auth = app.auth([() => {}]) expectType(auth) - app.get('/secret', { preHandler: auth }, (request, reply) => {}) - app.get('/private', { preHandler: [auth] }, (request, reply) => {}) + app.get('/secret', { preHandler: auth }, () => {}) + app.get('/private', { preHandler: [auth] }, () => {}) }) const typebox = fastify().withTypeProvider() @@ -99,7 +99,7 @@ async function usersController (fastify: FastifyInstance): Promise { usersMutationAccessPolicy(fastify), ]), }, - async (req, res) => ({ success: true }) + async () => ({ success: true }) ) } await usersController(app) @@ -113,7 +113,7 @@ async function usersControllerV2 (fastify: FastifyInstance): Promise { { onRequest: usersMutationAccessPolicy(fastify), }, - async (req, res) => ({ success: true }) + async () => ({ success: true }) ) } await usersControllerV2(app)