Skip to content

Commit

Permalink
Merge pull request #468 from pelias/greenkeeper/@hapi/joi-16.0.1
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 b0635f1 + d659d53 commit 71161f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
},
"homepage": "https://github.com/pelias/whosonfirst#readme",
"dependencies": {
"@hapi/joi": "^16.1.8",
"async": "^3.0.1",
"better-sqlite3": "^5.0.0",
"combined-stream": "^1.0.5",
"csv-stream": "^0.2.0",
"download-file-sync": "^1.0.4",
"fs-extra": "^8.0.0",
"iso3166-1": "^0.5.0",
"@hapi/joi": "^15.0.0",
"klaw-sync": "^6.0.0",
"lodash": "^4.5.1",
"parallel-transform": "^1.1.0",
Expand Down
24 changes: 12 additions & 12 deletions schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ const Joi = require('@hapi/joi');
// * imports.whosonfirst.missingFilesAreFatal (boolean) (default: false)

module.exports = Joi.object().keys({
imports: Joi.object().keys({
whosonfirst: Joi.object().keys({
imports: Joi.object().required().keys({
whosonfirst: Joi.object().required().keys({
dataHost: Joi.string(),
datapath: Joi.string(),
datapath: Joi.string().required(),
importPlace: [
Joi.number().integer(),
Joi.array().items(Joi.number().integer())
],
importVenues: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true),
importPostalcodes: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true),
importConstituencies: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true),
importIntersections: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true),
missingFilesAreFatal: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true),
importVenues: Joi.boolean().default(false).truthy('yes').falsy('no'),
importPostalcodes: Joi.boolean().default(false).truthy('yes').falsy('no'),
importConstituencies: Joi.boolean().default(false).truthy('yes').falsy('no'),
importIntersections: Joi.boolean().default(false).truthy('yes').falsy('no'),
missingFilesAreFatal: Joi.boolean().default(false).truthy('yes').falsy('no'),
maxDownloads: Joi.number().integer(),
sqlite: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true)
}).requiredKeys('datapath').unknown(false)
}).requiredKeys('whosonfirst').unknown(true)
}).requiredKeys('imports').unknown(true);
sqlite: Joi.boolean().default(false).truthy('yes').falsy('no')
}).unknown(false)
}).unknown(true)
}).unknown(true);
57 changes: 26 additions & 31 deletions test/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ const Joi = require('@hapi/joi');
const schema = require('../schema');

function validate(config) {
Joi.validate(config, schema, (err, value) => {
if (err) {
throw new Error(err.details[0].message);
}
});
const result = schema.validate(config);
if (result.error) {
throw new Error(result.error.details[0].message);
}
}

tape('tests for looking up hierarchies', function(test) {
Expand All @@ -22,7 +21,7 @@ tape('tests for looking up hierarchies', function(test) {
}
};

t.throws(validate.bind(null, config), /"datapath" is required/, 'missing datapath should throw');
t.throws(validate.bind(null, config), /"imports.whosonfirst.datapath" is required/, 'missing datapath should throw');
t.end();

});
Expand Down Expand Up @@ -52,7 +51,7 @@ tape('tests for looking up hierarchies', function(test) {
}
};

t.throws(validate.bind(null, config), /"spurious_key" is not allowed/);
t.throws(validate.bind(null, config), /"imports.whosonfirst.spurious_key" is not allowed/);
t.end();

});
Expand All @@ -67,7 +66,7 @@ tape('tests for looking up hierarchies', function(test) {
}
};

t.throws(validate.bind(null, config), /"datapath" must be a string/);
t.throws(validate.bind(null, config), /"imports.whosonfirst.datapath" must be a string/);

});

Expand All @@ -86,7 +85,7 @@ tape('tests for looking up hierarchies', function(test) {
}
};

t.throws(validate.bind(null, config), /"importVenues" must be a boolean/);
t.throws(validate.bind(null, config), /"imports.whosonfirst.importVenues" must be a boolean/);
});

t.end();
Expand All @@ -104,7 +103,7 @@ tape('tests for looking up hierarchies', function(test) {
}
};

t.throws(validate.bind(null, config), /"importPostalcodes" must be a boolean/);
t.throws(validate.bind(null, config), /"imports.whosonfirst.importPostalcodes" must be a boolean/);
});

t.end();
Expand All @@ -122,7 +121,7 @@ tape('tests for looking up hierarchies', function(test) {
}
};

t.throws(validate.bind(null, config), /"missingFilesAreFatal" must be a boolean/);
t.throws(validate.bind(null, config), /"imports.whosonfirst.missingFilesAreFatal" must be a boolean/);
});

t.end();
Expand Down Expand Up @@ -251,7 +250,7 @@ tape('battery of importPlace tests', test => {
}
};

const validated = Joi.validate(config, schema);
const validated = schema.validate(config);

t.equals(validated.value.imports.whosonfirst.importPlace, 123);
t.end();
Expand All @@ -268,7 +267,7 @@ tape('battery of importPlace tests', test => {
}
};

const validated = Joi.validate(config, schema);
const validated = schema.validate(config);

t.deepEquals(validated.value.imports.whosonfirst.importPlace, [123,456]);
t.end();
Expand All @@ -285,7 +284,7 @@ tape('battery of importPlace tests', test => {
}
};

const validated = Joi.validate(config, schema);
const validated = schema.validate(config);

t.equals(validated.value.imports.whosonfirst.importPlace, 123);
t.end();
Expand All @@ -302,7 +301,7 @@ tape('battery of importPlace tests', test => {
}
};

const validated = Joi.validate(config, schema);
const validated = schema.validate(config);

t.deepEquals(validated.value.imports.whosonfirst.importPlace, [123, 456]);
t.end();
Expand All @@ -320,11 +319,10 @@ tape('battery of importPlace tests', test => {
}
};

const result = Joi.validate(config, schema);
const validated = schema.validate(config);

t.equals(result.error.details.length, 2);
t.equals(result.error.details[0].message, '"importPlace" must be a number');
t.equals(result.error.details[1].message, '"importPlace" must be an array');
t.equals(validated.error.details.length, 1);
t.equals(validated.error.details[0].message, '"imports.whosonfirst.importPlace" must be one of [number, array]');

});

Expand All @@ -343,11 +341,10 @@ tape('battery of importPlace tests', test => {
}
};

const result = Joi.validate(config, schema);
const validated = schema.validate(config);

t.equals(result.error.details.length, 2);
t.equals(result.error.details[0].message, '"importPlace" must be a number');
t.equals(result.error.details[1].message, '"0" must be a number');
t.equals(validated.error.details.length, 1);
t.equals(validated.error.details[0].message, '"imports.whosonfirst.importPlace[0]" must be a number');

});

Expand All @@ -365,11 +362,10 @@ tape('battery of importPlace tests', test => {
}
};

const result = Joi.validate(config, schema);
const validated = schema.validate(config);

t.equals(result.error.details.length, 2);
t.equals(result.error.details[0].message, '"importPlace" must be an integer');
t.equals(result.error.details[1].message, '"importPlace" must be an array');
t.equals(validated.error.details.length, 1);
t.equals(validated.error.details[0].message, '"imports.whosonfirst.importPlace" must be an integer');
t.end();

});
Expand All @@ -384,11 +380,10 @@ tape('battery of importPlace tests', test => {
}
};

const result = Joi.validate(config, schema);
const validated = schema.validate(config);

t.equals(result.error.details.length, 2);
t.equals(result.error.details[0].message, '"importPlace" must be a number');
t.equals(result.error.details[1].message, '"0" must be an integer');
t.equals(validated.error.details.length, 1);
t.equals(validated.error.details[0].message, '"imports.whosonfirst.importPlace[0]" must be an integer');
t.end();

});
Expand Down

0 comments on commit 71161f5

Please sign in to comment.