test('gun namespace should exist', t => { t.plan(3) const fastify = Fastify() fastify .register(gunPlugin, { name: 'test' }) .ready(err => { t.error(err) t.ok(fastify.gun) fastify.close(() => { t.pass('unlock') }) }) })
function build (t) { const app = Fastify() app.register(fp(App), config()) t.tearDown(app.close.bind(app)) return app }
test('support works standalone', async (t) => { const fastify = Fastify() fastify.register(Support) await fastify.ready() t.equal(fastify.someSupport(), 'here support') })
test('Sequelize instance name should work', t => { t.plan(2) const fastify = Fastify() fastify.register(fastifySequelize, { instance: 'db', // instance name dialect: 'sqlite', storage: resolve(__dirname, 'db.sqlite') }) fastify.ready(err => { t.error(err) t.ok(fastify.db) // instance name fastify.db.close() fastify.close() }) })
}) const fastify = Fastify()
test('should throw an error "request.user does not exist" non existing request.user', function (t) { t.plan(4) var fastify = Fastify() fastify.register(jwtAuthz) fastify.get('/test3', function (request, reply) { request.jwtAuthz('baz') .catch(err => t.match(err.message, 'request.user does not exist')) reply.send({ foo: 'bar' }) }) fastify.listen(0, function (err) { fastify.server.unref() t.error(err) request({ method: 'GET', uri: 'http://localhost:' + fastify.server.address().port + '/test3', json: true }, function (err, response) { t.error(err) t.ok(response) }) }) })
test('should decorate request instance with jwtAuthz method', function (t) { t.plan(4) var fastify = Fastify() fastify.register(jwtAuthz) fastify.get('/test', function (request, reply) { t.ok(request.jwtAuthz) reply.send({ foo: 'bar' }) }) fastify.listen(0, function (err) { fastify.server.unref() t.error(err) request({ method: 'GET', uri: 'http://localhost:' + fastify.server.address().port + '/test', json: true }, function (err, response) { t.error(err) t.ok(response) }) }) })
test('gun should support gundb operations', t => { t.plan(2) const fastify = Fastify() fastify .register(gunPlugin, { name: 'test' }) .ready(err => { t.error(err) fastify.gun.get('test').set('d').once(function (val) { if (!val) t.error('no data') t.equal('d', val) }) }) })
test('Sequelize should close connection before Fastify closed', t => { t.plan(2) const fastify = Fastify() fastify.register(fastifySequelize, { dialect: 'sqlite', storage: resolve(__dirname, 'db.sqlite') }) fastify.ready(err => { t.error(err) fastify.close(() => { fastify .sequelize .authenticate() .then(() => { t.error('connection not closed !') }) .catch(err => { t.ok(err) }); }) }) })
test('support works standalone', (t) => { t.plan(2) const fastify = Fastify() fastify.register(Support) fastify.ready((err) => { t.error(err) t.equal(fastify.someSupport(), 'hugs') }) })
test('fastify.sequelize should exist', t => { t.plan(2) const fastify = Fastify() fastify.register(fastifySequelize, { dialect: 'sqlite', storage: resolve(__dirname, 'db.sqlite') }) fastify.ready(err => { t.error(err) t.ok(fastify.sequelize) fastify.sequelize.close() fastify.close() }) })
test('support works standalone', async (t) => { const fastify = Fastify() fastify.register(Support) await fastify.ready() t.equal(fastify.someSupport(), 'here support') })
function build (t) { const app = Fastify() app.register(fp(App), config()) t.tearDown(app.close.bind(app)) return app }
// automatically build and tear down our instance function build (t) { const app = Fastify() // fastify-plugin ensures that all decorators // are exposed for testing purposes, this is // different from the production setup app.register(fp(App), config()) // tear down our app after we are done t.tearDown(app.close.bind(app)) return app }
test('should throw an error "Scopes cannot be empty" with an empty scopes parameter', function (t) { t.plan(4) var fastify = Fastify() fastify.register(jwtAuthz) fastify.get('/test2', function (request, reply) { request.jwtAuthz([]) .catch(err => t.match(err.message, 'Scopes cannot be empty')) reply.send({ foo: 'bar' }) }) fastify.listen(0, function (err) { fastify.server.unref() t.error(err) request({ method: 'GET', uri: 'http://localhost:' + fastify.server.address().port + '/test2', json: true }, function (err, response) { t.error(err) t.ok(response) }) }) })