mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
Implemented global validation on defined fields (#9992)
no-issue This is to allow global validation to run on fields that have some user validation defined.
This commit is contained in:
parent
7a73dfd9bc
commit
caccda1aab
@ -38,6 +38,11 @@ const validate = (config, attrs) => {
|
||||
_.each(attrs, (value, key) => {
|
||||
debug(key, value);
|
||||
|
||||
if (GLOBAL_VALIDATORS[key]) {
|
||||
debug('global validation');
|
||||
errors = errors.concat(validation.validate(value, key, GLOBAL_VALIDATORS[key]));
|
||||
}
|
||||
|
||||
if (config && config[key]) {
|
||||
const allowedValues = Array.isArray(config[key]) ? config[key] : config[key].values;
|
||||
|
||||
@ -53,9 +58,6 @@ const validate = (config, attrs) => {
|
||||
errors.push(new common.errors.ValidationError());
|
||||
}
|
||||
}
|
||||
} else if (GLOBAL_VALIDATORS[key]) {
|
||||
debug('global validation');
|
||||
errors = errors.concat(validation.validate(value, key, GLOBAL_VALIDATORS[key]));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -38,6 +38,29 @@ describe('Unit: api/shared/validators/input/all', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should run global validations on an type that has validation defined', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
slug: 'not a valid slug %%%%% http://',
|
||||
}
|
||||
};
|
||||
|
||||
const apiConfig = {
|
||||
options: {
|
||||
slug: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return shared.validators.input.all.all(apiConfig, frame)
|
||||
.then(() => {
|
||||
throw new Error('Should not resolve');
|
||||
}, (err) => {
|
||||
should.exist(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('default include array notation', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
|
Loading…
Reference in New Issue
Block a user