Fixed incorrect validation message for required values

no issue

- the message always showed: `Validation (FieldIsRequired) failed for key`
This commit is contained in:
kirrg001 2018-12-10 15:13:52 +01:00 committed by Katharina Irrgang
parent da7fdfeae6
commit 11f0f1c314
2 changed files with 9 additions and 3 deletions

View File

@ -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)
})
}));
}

View File

@ -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"]');
});
});