it('should return an error if wrong type is passed to refreshStoreOlderThan', { plan: 1 }, (done) => { const Store = require('../../lib/store'); Store.refreshStoreOlderThan('not a number',(err) => { expect(err).to.exist(); done(); }); });
describe('Utils', () => { it('promisify returns a promise if no callback', (done) => { const functionWithoutCallback = function (params){ }; const promise = Utils.promisify(this, functionWithoutCallback, 123); expect(promise).to.be.an.object(); expect(promise.then).to.be.a.function(); expect(promise.catch).to.be.a.function(); done(); }); });
it('should properly create a GraphQL data type and support complex required fields', async () => { const joiSchema = object().keys({ a: number().integer().required() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.deep.equal( new GraphQLNonNull(GraphQLInt) ); });
it('should handle configuration error', async () => { try { await startServer({name, version, init, port: -1}) } catch (err) { assert(err instanceof Error) assert(err.message.includes('"port" must be larger than or equal to 0')) return } throw new Error('should have failed') })
describe('API tests for application', () => { it('returns success for home route', async () => { const response = await Server.inject({ method: 'GET', url: '/' }); expect(response.statusCode).to.equal(200); expect(response.result).to.equal({ success: true }); }); });
it('should not complain about big payload', {timeout: 5e3}, async () => { const name = Array.from({length: 1024 * 1024 * 10}, () => 'a').join('') const greetings = await request({ method: 'POST', url: `${server.info.uri}/api/sample/greeting`, body: {name}, json: true }) assert(greetings) })
it('should properly create a GraphQL data type and support string scalar types', async () => { const joiSchema = object().keys({ a: string() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLString ); });
it('should error when joi schema is not provided', async () => { const subject = () => { Joi2GQL.type(); }; expect(subject).to.throw(Error, 'schema argument must be defined'); });
it('should invoke API without argument', async () => { const {time} = await request({ method: 'GET', url: `${server.info.uri}/api/sample/ping`, json: true }) assert(typeof time === 'string') })
it('should error when using array type without specifying a scalar type as an item', async () => { const joiSchema = object().keys({ a: array() }); const subject = () => { Joi2GQL.type(joiSchema); }; expect(subject).to.throw(Error, 'Need to provide scalar type as an item when using joi array'); });
it('should throw when joi schema is not of Joi type object', async () => { const joiSchema = string(); const subject = () => { Joi2GQL.type(joiSchema); }; expect(subject).to.throw(Error, 'schema must be a Joi Object type'); });
it('should assign name to Anon if one was not given', async () => { const joiSchema = object().keys({ a: string(), b: number().integer() }); Joi2GQL.type(joiSchema).name.should.equal('Anon'); });
it('should properly create a GraphQL data type and support list scalar types', async () => { const joiSchema = object().keys({ a: array().items(string()) }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.deep.equal( new GraphQLList(GraphQLString) ); });
it('should throw when passed an invalid config', async () => { const joiSchema = object(); const subject = () => { Joi2GQL.type(joiSchema, true); }; expect(subject).to.throw(Error, '"value" must be an object'); });
it('should handle missing version', async () => { try { await startServer({name, init}) } catch (err) { assert(err instanceof Error) assert(err.message.includes('"name" and "version" options')) return } throw new Error('should have failed') })