Add some more rules

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-02-17 14:51:21 +01:00
parent 59fc06e024
commit 780f2695df
5 changed files with 11 additions and 10 deletions

View File

@ -4,4 +4,5 @@ module.exports = {
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
printWidth: 100,
};

View File

@ -52,6 +52,9 @@
"plugin": "upload",
"required": false
},
"timestamp": {
"type": "timestamp"
},
"images": {
"collection": "file",
"via": "related",

View File

@ -3,8 +3,10 @@
const yup = require('yup');
const _ = require('lodash');
function isDefined(msg = '${path} must be defined') {
return this.test('defined', msg, value => !_.isNil(value));
const isNotNil = value => !_.isNil(value);
function isDefined(msg = '${path} must be defined.') {
return this.test('defined', msg, isNotNil);
}
yup.addMethod(yup.mixed, 'defined', isDefined);

View File

@ -28,10 +28,7 @@ describe('Entity validator', () => {
expect.hasAssertions();
await entityValidator.validateEntity(model, input).catch(() => {
expect(errors.badRequest).toHaveBeenCalledWith(
'ValidationError',
expect.any(Object)
);
expect(errors.badRequest).toHaveBeenCalledWith('ValidationError', expect.any(Object));
});
});

View File

@ -35,9 +35,7 @@ const enumerationValidator = attr => {
.oneOf(Array.isArray(attr.enum) ? attr.enum : [attr.enum]);
};
const emailValidator = composeValidators(stringValidator, (attr, validator) =>
validator.email()
);
const emailValidator = composeValidators(stringValidator, (attr, validator) => validator.email());
const minIntegerValidator = ({ min }, validator) =>
_.isNumber(min) ? validator.min(_.toInteger(min)) : validator;
@ -78,7 +76,7 @@ module.exports = {
password: stringValidator,
email: emailValidator,
enumeration: enumerationValidator,
boolean: () => yup.boolean(),
boolean: () => yup.boolean().nullable(),
uid: uidValidator,
json: () => yup.mixed(),
integer: integerValidator,