Browse Source

allow libpostal configuration in schema w/other services

pull/1061/head
Stephen Hess 7 years ago
parent
commit
f56deffb8f
  1. 5
      schema.js
  2. 15
      test/unit/schema.js

5
schema.js

@ -41,6 +41,11 @@ module.exports = Joi.object().keys({
url: Joi.string().uri({ scheme: /https?/ }),
timeout: Joi.number().integer().optional().default(250).min(0),
retries: Joi.number().integer().optional().default(3).min(0),
}).unknown(false).requiredKeys('url'),
libpostal: Joi.object().keys({
url: Joi.string().uri({ scheme: /https?/ }),
timeout: Joi.number().integer().optional().default(250).min(0),
retries: Joi.number().integer().optional().default(3).min(0),
}).unknown(false).requiredKeys('url')
}).unknown(false).default({}), // default api.services to an empty object
defaultParameters: Joi.object().keys({

15
test/unit/schema.js

@ -28,6 +28,9 @@ module.exports.tests.completely_valid = (test, common) => {
},
interpolation: {
url: 'http://localhost'
},
libpostal: {
url: 'http://localhost'
}
},
defaultParameters: {
@ -419,7 +422,7 @@ module.exports.tests.api_validation = (test, common) => {
});
// api.pipService has been moved to api.services.pip.url
test('any api.pipService value should be allowed', (t) => {
test('any api.pipService value should fail', (t) => {
[null, 17, {}, [], true, 'http://localhost'].forEach((value) => {
var config = {
api: {
@ -543,7 +546,7 @@ module.exports.tests.api_services_validation = (test, common) => {
module.exports.tests.service_validation = (test, common) => {
// these tests apply for all the individual service definitions
const services = ['pip', 'placeholder', 'interpolation'];
const services = ['pip', 'placeholder', 'interpolation', 'libpostal'];
test('timeout and retries not specified should default to 250 and 3', (t) => {
services.forEach(service => {
@ -572,7 +575,7 @@ module.exports.tests.service_validation = (test, common) => {
});
test('when api.services.service is defined, url is required', (t) => {
test('when api.services.<service> is defined, url is required', (t) => {
services.forEach(service => {
const config = {
api: {
@ -596,7 +599,7 @@ module.exports.tests.service_validation = (test, common) => {
});
test('non-string api.services.pip.url should throw error', (t) => {
test('non-string api.services.<service>.url should throw error', (t) => {
services.forEach(service => {
[null, 17, {}, [], true].forEach(value => {
const config = {
@ -626,7 +629,7 @@ module.exports.tests.service_validation = (test, common) => {
});
test('non-http/https api.services.pip.url should throw error', (t) => {
test('non-http/https api.services.<service>.url should throw error', (t) => {
services.forEach(service => {
['ftp', 'git', 'unknown'].forEach((scheme) => {
const config = {
@ -656,7 +659,7 @@ module.exports.tests.service_validation = (test, common) => {
});
test('non-url children of api.services.pip should be disallowed', (t) => {
test('non-url/timeout/retries children of api.services.<service> should be disallowed', (t) => {
services.forEach(service => {
const config = {
api: {

Loading…
Cancel
Save