Comparing version 0.0.9 to 0.0.10
@@ -52,6 +52,2 @@ // Load modules | ||
else { | ||
if(options.convert) { | ||
object[key] = value; | ||
} | ||
delete submitted[key]; | ||
@@ -58,0 +54,0 @@ } |
@@ -53,14 +53,3 @@ // Load modules | ||
var valid = false; | ||
self._traverse(value, self._config, function (isValid) { | ||
if (!isValid) { | ||
return false; | ||
} | ||
valid = isValid; | ||
}); | ||
return valid; | ||
return self._traverse(value, self._config); | ||
}; | ||
@@ -77,28 +66,25 @@ }; | ||
internals.ObjectType.prototype._traverse = function (obj, config, callback) { | ||
internals.ObjectType.prototype._traverse = function (obj, config) { | ||
var self = this; | ||
var traversing = false; | ||
var keys = Object.keys(config); | ||
Object.keys(config).forEach(function (key) { | ||
for (var i = 0, il = keys.length; i < il; ++i) { | ||
var key = keys[i]; | ||
var itemConfig = config[key]; | ||
var value = obj ? obj[key] : null; | ||
if (itemConfig.type === 'Object') { | ||
traversing = true; | ||
self._traverse(value, itemConfig._config, callback); | ||
} | ||
else if (typeof itemConfig.validate === 'function' && | ||
if (typeof itemConfig.validate === 'function' && | ||
itemConfig.validate(value) === false) { | ||
traversing = true; | ||
return callback(false); | ||
return false; | ||
} | ||
}); | ||
if (!traversing) { | ||
callback(true); | ||
if (itemConfig.type === 'Object') { | ||
self._traverse(value, itemConfig._config); | ||
} | ||
} | ||
return true; | ||
}; |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"author": "Van Nguyen <the.gol.effect@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -15,2 +15,3 @@ // Load modules | ||
var expect = Chai.expect; | ||
var T = Joi.Types; | ||
@@ -198,4 +199,43 @@ | ||
}); | ||
it('should work with null options', function (done) { | ||
var schema = { item: Joi.types.Number() }; | ||
var input = { item: '1' }; | ||
Joi.validate(input, schema, null, function (err) { | ||
expect(err).to.not.exist; | ||
expect(input.item).to.equal('1'); | ||
done(); | ||
}); | ||
}); | ||
it('should fail validation when a child object has an invalid string value but object traversal isn\'t complete', function (done) { | ||
var input = { method: 'GET', path: '/', config: { payload: 'something' } }; | ||
Joi.validate(input, internals.routeSchema, function (err) { | ||
expect(err).to.exist; | ||
done(); | ||
}); | ||
}); | ||
internals.routeSchema = { | ||
method: T.String().invalid('head').required(), | ||
path: T.String().required(), | ||
handler: [T.Object().optional(), T.Function().optional(), T.String().valid('notFound').optional()], | ||
config: T.Object({ | ||
handler: [T.Object().optional(), T.Function().optional(), T.String().valid('notFound').optional()], | ||
payload: T.String().valid(['stream', 'raw', 'parse']).optional(), | ||
response: T.Object({ | ||
schema: T.Object().nullOk().optional(), | ||
sample: T.Number().optional(), | ||
failAction: T.String().optional().valid(['error', 'log', 'ignore']) | ||
}).optional() | ||
}) | ||
}; | ||
}); | ||
@@ -43,2 +43,9 @@ // Load modules | ||
it('should convert a non-array string to an array', function (done) { | ||
var result = A().convert('{ "something": false }'); | ||
expect(result.length).to.equal(1); | ||
done(); | ||
}); | ||
it('should return a non array', function (done) { | ||
@@ -45,0 +52,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
273440
2885