mirror of
https://github.com/strapi/strapi.git
synced 2026-01-07 12:45:45 +00:00
Add some more rules
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
59fc06e024
commit
780f2695df
@ -4,4 +4,5 @@ module.exports = {
|
||||
singleQuote: true,
|
||||
tabWidth: 2,
|
||||
trailingComma: 'es5',
|
||||
printWidth: 100,
|
||||
};
|
||||
|
||||
@ -52,6 +52,9 @@
|
||||
"plugin": "upload",
|
||||
"required": false
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "timestamp"
|
||||
},
|
||||
"images": {
|
||||
"collection": "file",
|
||||
"via": "related",
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user