Skip to content

Commit

Permalink
fix: make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Sep 14, 2019
1 parent 5434ac3 commit 52da1d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert');
var defaultMessage = 'valid mongo id';

module.exports = function joiObjectId(Joi, message) {
assert(Joi && Joi.isJoi, 'you must pass Joi as an argument');
assert(Joi && Joi.object, 'you must pass Joi as an argument');
if (message == undefined) {
message = defaultMessage;
}
Expand Down
9 changes: 5 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var assert = require('assert');
var Joi = require('joi');
var Joi = require('@hapi/joi');
var joiObjectId = require('./');

describe('joi-objectid', function() {
Expand Down Expand Up @@ -33,10 +33,10 @@ describe('joi-objectid', function() {
, { val: { length: 24 } , pass: false }
]

var schema = { val: oid() };
var schema = oid();

tests.forEach(function(test) {
var res = Joi.validate({ val: test.val }, schema);
var res = schema.validate(test.val);
assert(test.pass === ! res.error, res.error);
});

Expand All @@ -45,7 +45,8 @@ describe('joi-objectid', function() {

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

assert(result.error);
assert(result.error.message.indexOf('database id') >= 0);
Expand Down

0 comments on commit 52da1d7

Please sign in to comment.