Skip to content

Commit

Permalink
Merge pull request #272 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 2edc310 + 1dd7718 commit 915a12d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"who's on first"
],
"dependencies": {
"@hapi/joi": "^16.1.8",
"async": "^3.0.1",
"csv-parse": "^4.0.0",
"@hapi/joi": "^15.0.0",
"lodash": "^4.17.4",
"parallel-transform": "^1.1.0",
"pelias-config": "^4.0.0",
Expand Down
14 changes: 7 additions & 7 deletions schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Joi = require('@hapi/joi');
const cpus = require('os').cpus;

module.exports = Joi.object().keys({
imports: Joi.object().keys({
imports: Joi.object().required().keys({
adminLookup: Joi.object().keys({
// default maxConcurrentReqs to # of cpus/cores * 10
maxConcurrentReqs: Joi.number().integer().default(cpus().length*10),
Expand All @@ -11,17 +11,17 @@ module.exports = Joi.object().keys({
usePostalCities: Joi.boolean().default(false)
}).unknown(true),
whosonfirst: Joi.object().keys({
datapath: Joi.string(),
datapath: Joi.string().required(),
importPlace: [
Joi.number().integer(),
Joi.array().items(Joi.number().integer())
],
sqlite: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true)
}).requiredKeys('datapath').unknown(true),
sqlite: Joi.boolean().default(false).truthy('yes').falsy('no')
}).unknown(true),
services: Joi.object().keys({
pip: Joi.object().keys({
url: Joi.string()
}).requiredKeys('url').unknown(true)
url: Joi.string().required()
}).unknown(true)
}).unknown(true)
}).or('whosonfirst', 'services.pip').unknown(true)
}).requiredKeys('imports').unknown(true);
}).unknown(true);
66 changes: 33 additions & 33 deletions test/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tape('test configuration scenarios', (test) => {
test.test('missing imports should throw error', (t) => {
const config = {};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"imports" is required');
Expand All @@ -19,10 +19,10 @@ tape('test configuration scenarios', (test) => {
[null, 17, 'string', [], true].forEach((value) => {
const config = { imports: value };

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"imports" must be an object');
t.equals(result.error.details[0].message, '"imports" must be of type object');
});

t.end();
Expand All @@ -34,10 +34,10 @@ tape('test configuration scenarios', (test) => {
imports: {}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"value" must contain at least one of [whosonfirst, services.pip]');
t.equals(result.error.details[0].message, '"imports" must contain at least one of [whosonfirst, services.pip]');
t.end();

});
Expand All @@ -49,10 +49,10 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"datapath" is required');
t.equals(result.error.details[0].message, '"imports.whosonfirst.datapath" is required');
t.end();

});
Expand All @@ -66,7 +66,7 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.notOk(result.error);
t.end();
Expand All @@ -84,10 +84,10 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"adminLookup" must be an object');
t.equals(result.error.details[0].message, '"imports.adminLookup" must be of type object');
});

t.end();
Expand All @@ -107,10 +107,10 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"maxConcurrentReqs" must be a number');
t.equals(result.error.details[0].message, '"imports.adminLookup.maxConcurrentReqs" must be a number');

});

Expand All @@ -130,10 +130,10 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"maxConcurrentReqs" must be an integer');
t.equals(result.error.details[0].message, '"imports.adminLookup.maxConcurrentReqs" must be an integer');
t.end();

});
Expand All @@ -149,7 +149,7 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.value.imports.adminLookup.maxConcurrentReqs, os.cpus().length*10);
t.notOk(result.error);
Expand All @@ -171,10 +171,10 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"enabled" must be a boolean');
t.equals(result.error.details[0].message, '"imports.adminLookup.enabled" must be a boolean');

});

Expand All @@ -196,7 +196,7 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.notOk(result.error);

Expand All @@ -218,7 +218,7 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.notOk(result.error);
t.equals(result.value.imports.adminLookup.enabled, true);
Expand All @@ -240,10 +240,10 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"missingMetafilesAreFatal" must be a boolean');
t.equals(result.error.details[0].message, '"imports.adminLookup.missingMetafilesAreFatal" must be a boolean');

});

Expand All @@ -265,7 +265,7 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.notOk(result.error);

Expand All @@ -287,7 +287,7 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.notOk(result.error);
t.equals(result.value.imports.adminLookup.missingMetafilesAreFatal, false);
Expand All @@ -307,7 +307,7 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.notOk(result.error);
t.end();
Expand All @@ -324,10 +324,10 @@ tape('test configuration scenarios', (test) => {
}
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"datapath" must be a string');
t.equals(result.error.details[0].message, '"imports.whosonfirst.datapath" must be a string');
});

t.end();
Expand All @@ -350,7 +350,7 @@ tape('test configuration scenarios', (test) => {
unknown_property: 'property value'
};

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

t.notOk(result.error);
t.end();
Expand All @@ -364,10 +364,10 @@ tape('test configuration scenarios', (test) => {
},
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"value" must contain at least one of [whosonfirst, services.pip]');
t.equals(result.error.details[0].message, '"imports" must contain at least one of [whosonfirst, services.pip]');
t.end();

});
Expand All @@ -379,10 +379,10 @@ tape('test configuration scenarios', (test) => {
},
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"url" is required');
t.equals(result.error.details[0].message, '"imports.services.pip.url" is required');
t.end();

});
Expand All @@ -397,10 +397,10 @@ tape('test configuration scenarios', (test) => {
},
};

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

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"url" must be a string');
t.equals(result.error.details[0].message, '"imports.services.pip.url" must be a string');
});

t.end();
Expand Down

0 comments on commit 915a12d

Please sign in to comment.