function validationMiddlware(req) { return Joi.validate( req.payload.pattern.message, Joi.object() .keys({ from: Joi.string().required(), to: Joi.string().required(), subject: Joi.string().required(), text: Joi.string().optional(), html: Joi.string().optional(), bcc: Joi.string().optional(), cc: Joi.string().optional() }) .required() ) }
/** * * * @static * @param {any} topic * @returns * * @memberOf StorePattern */ static find(topic) { return { topic, cmd: 'find', collection: Joi.string().required(), query: Joi.object().required(), options: Joi.object() .keys({ fields: Joi.alternatives().try(Joi.object(), Joi.array()), orderBy: Joi.alternatives().try(Joi.object(), Joi.array(), Joi.string()), offset: Joi.number().integer(), limit: Joi.number().integer() }) .default({}) } }
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) ); });
Joi.object().keys({ id : Joi.number().integer(), firstname : Joi.string().max(128).optional(), lastname : Joi.string().max(128).optional(), created_at : Joi.date().default(() => moment().format(), 'date created'), updated_at : Joi.date().default(() => moment().format(), 'date updated'), })
Joi.array().items(Joi.object().keys({ name: Joi.string().required(), value: Joi.required() })).unique((a, b) => a.name === b.name)
it('should properly create a GraphQL data type and support int scalar types', async () => { const joiSchema = object().keys({ a: number().integer() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLInt ); });
/** * Used to validate configs (or any objects for that matter) using a Joi schema. * * @see https://github.com/hapijs/joi * @param {SchemaMap|object} schema * @param {object} object * @param {string} label * @return {object} */ static validate(schema, object, label = 'data') { const fullSchema = Joi.object().required().keys(schema); return Util.validateFull(fullSchema, object, label); }
validate(p){ const schema = Joi.object().keys({ id: Joi.number().integer(), name: Joi.string().min(3).max(30).required(), price: Joi.number().precision(2).required() }); const {error} = Joi.validate(p, schema); if(error){ return error.details[0].message; } return null; }
it('should properly create a GraphQL data type and support boolean scalar types', async () => { const joiSchema = object().keys({ a: boolean() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLBoolean ); });
it('should properly create a GraphQL data type and support required fields', async () => { const joiSchema = object().keys({ a: number().required() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.deep.equal( new GraphQLNonNull(GraphQLFloat) ); });
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 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 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 properly create a GraphQL data type and support id scalar types', async () => { const joiSchema = object().keys({ a: string().guid() }); Joi2GQL.type(joiSchema)._typeConfig.fields.a.type.should.equal( GraphQLID ); });
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 ); });