Skip to content

Commit

Permalink
Fix message/defaultMessage handling and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jlai committed Dec 16, 2016
1 parent 6d3c80b commit 2212ab0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ module.exports = function joiObjectId(Joi, message) {
message = defaultMessage;
}
return function objectId() {
return Joi.string().regex(/^[0-9a-fA-F]{24}$/, defaultMessage);
return Joi.string().regex(/^[0-9a-fA-F]{24}$/, message);
};
};
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ describe('joi-objectid', function() {

done();
});

it('includes custom message for invalid value', function(done) {
var dbId = joiObjectId(Joi, 'database id');
var result = Joi.validate('blah', dbId());

assert(result.error);
assert(result.error.message.indexOf('database id') >= 0);
done();
});
});

0 comments on commit 2212ab0

Please sign in to comment.