Skip to content

Commit

Permalink
Test compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole Panike committed Dec 16, 2019
1 parent 495ce3c commit 571da6c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/auto-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module.exports.getFiles = (baseDir, pattern) => {

if (Array.isArray(baseDir)) {
const promise = new Promise((resolve, reject) => {

Promise.all(baseDir.map((d) => this.getFiles(d, pattern)))
.then((value) => resolve(Hoek.flatten(value)))
.catch((reason) => reject(reason));
})
.then((value) => resolve(Hoek.flatten(value)));
});
return promise;
}

Expand All @@ -27,18 +27,19 @@ module.exports.getRoutes = (filepaths) => {

const routeSchema = Joi.object().keys({
method: Joi.string().required(),
path: Joi.string().required(),
path: Joi.string().required()
// Technically handler is required as well, either in the method or in its options, but that gets sticky with plugins.
}).xor('handler', 'options').unknown(true);

const multipleRoutesAllowed = Joi.alternatives(routeSchema, Joi.array().items(routeSchema));

const files = filepaths.map(p => require(Path.resolve(p)));
const files = filepaths.map((p) => require(Path.resolve(p)));

const routes = files.filter((file) => {

const routes = files.filter(file => {
const { error } = Joi.validate(file, multipleRoutesAllowed);
return error === null;
})
});

return routes.map((file) => Hoek.clone(file));
};
Expand Down

0 comments on commit 571da6c

Please sign in to comment.