Fixed incorrect validation message for required values
no issue - the message always showed: `Validation (FieldIsRequired) failed for key`
This commit is contained in:
parent
da7fdfeae6
commit
11f0f1c314
@ -118,14 +118,19 @@ module.exports = {
|
||||
const jsonpath = require('jsonpath');
|
||||
|
||||
if (apiConfig.data) {
|
||||
const missedDataProperties = _.filter(apiConfig.data, (value, key) => {
|
||||
return jsonpath.query(frame.data[apiConfig.docName][0], key).length === 0;
|
||||
const missedDataProperties = [];
|
||||
|
||||
_.each(apiConfig.data, (value, key) => {
|
||||
if (jsonpath.query(frame.data[apiConfig.docName][0], key).length === 0) {
|
||||
missedDataProperties.push(key);
|
||||
}
|
||||
});
|
||||
|
||||
if (missedDataProperties.length) {
|
||||
return Promise.reject(new common.errors.ValidationError({
|
||||
message: common.i18n.t('notices.data.validation.index.validationFailed', {
|
||||
validationName: 'FieldIsRequired'
|
||||
validationName: 'FieldIsRequired',
|
||||
key: JSON.stringify(missedDataProperties)
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
@ -328,6 +328,7 @@ describe('Unit: api/shared/validators/input/all', function () {
|
||||
.then(Promise.reject)
|
||||
.catch((err) => {
|
||||
should.exist(err);
|
||||
err.message.should.eql('Validation (FieldIsRequired) failed for ["b"]');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user