Skip to content

Commit

Permalink
Merge pull request #378 from pelias/greenkeeper/@hapi/joi-16.0.0
Browse files Browse the repository at this point in the history
Update @hapi/joi to the latest version 🚀
  • Loading branch information
orangejulius authored Nov 25, 2019
2 parents 66d5c13 + 9c655b1 commit 0bda195
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
25 changes: 11 additions & 14 deletions configValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ const Joi = require('@hapi/joi');
// Schema Configuration
// schema.indexName: populated by defaults if not overridden
// esclient: object, validation performed by elasticsearch module
const schema = Joi.object().keys({
schema: {
indexName: Joi.string(),
typeName: Joi.string()
},
esclient: Joi.object()
}).requiredKeys(
'schema', 'schema.indexName', 'schema.typeName', 'esclient'
).unknown(true);
const schema = Joi.object().required().keys({
schema: Joi.object().required().keys({
indexName: Joi.string().required(),
typeName: Joi.string().required()
}),
esclient: Joi.object().required()
}).unknown(true);

module.exports = {
validate: function validate(config) {
Joi.validate(config, schema, err => {
if (err) {
throw new Error(err.details[0].message);
}
});
const validated = schema.validate(config);
if (validated.error) {
throw new Error(validated.error.details[0].message);
}
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"elasticsearch": ">=1.1.1"
},
"dependencies": {
"@hapi/joi": "^15.1.1",
"@hapi/joi": "^16.1.8",
"colors": "^1.1.2",
"elasticsearch": "^16.0.0",
"lodash": "^4.17.15",
Expand Down
10 changes: 5 additions & 5 deletions test/configValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function() {
configValidation.validate(config);
}, /"indexName" is required/, 'schema.indexName should exist');
}, /"schema.indexName" is required/, 'schema.indexName should exist');
t.end();

});
Expand All @@ -38,7 +38,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function () {
configValidation.validate(config);
}, /"typeName" is required/, 'schema.typeName should exist');
}, /"schema.typeName" is required/, 'schema.typeName should exist');
t.end();

});
Expand All @@ -55,7 +55,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function() {
configValidation.validate(config);
}, /"indexName" must be a string/, 'schema.indexName should be a string');
}, /"schema.indexName" must be a string/, 'schema.indexName should be a string');

});

Expand All @@ -75,7 +75,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function () {
configValidation.validate(config);
}, /"typeName" must be a string/, 'schema.typeName should be a string');
}, /"schema.typeName" must be a string/, 'schema.typeName should be a string');

});

Expand All @@ -95,7 +95,7 @@ module.exports.tests.interface = function(test, common) {

t.throws(function() {
configValidation.validate(config);
}, /"esclient" must be an object/, 'esclient should be an object');
}, /"esclient" must be of type object/, 'esclient should be an object');

});

Expand Down

0 comments on commit 0bda195

Please sign in to comment.