Comparing version 0.0.4 to 0.0.5
@@ -15,2 +15,8 @@ // Load modules | ||
exports.settings = { | ||
skipFunctions: false, | ||
saveConversions: false, | ||
} | ||
exports.validate = function (object, config, next) { | ||
@@ -28,3 +34,2 @@ | ||
for (var i in elementKeys) { | ||
var finalizeFns = []; | ||
@@ -42,12 +47,12 @@ | ||
value = converter(value); | ||
if (this.settings.saveConversions == true) { | ||
object[key] = value; | ||
} | ||
} | ||
// console.log('whereami', i, key) | ||
// console.log(config[key].__checks) | ||
var result = config[key].validate(value, key, object, placeholder); | ||
// console.log("validating", key, object[key], value, config[key].type, result, placeholder) | ||
if (result === false) { | ||
isInvalid = true; | ||
errorMsg = key + ' = ' + value; | ||
// console.log(key, "failed to validate", value) | ||
} | ||
@@ -65,3 +70,12 @@ else { | ||
var processed = Object.keys(submitted); | ||
// console.log(object, submitted, processed) | ||
if (this.settings.skipFunctions == true) { | ||
for(var p in processed){ | ||
if (typeof submitted[processed[p]] == 'function') { | ||
delete submitted[processed[p]]; | ||
} | ||
} | ||
processed = Object.keys(submitted); | ||
} | ||
if (processed.length > 0) { | ||
@@ -77,5 +91,15 @@ | ||
} | ||
var processedValues = processed.map(function(d){ | ||
var value = "(" + typeof submitted[d] + ") "; | ||
value += submitted[d].toString(); | ||
var suffix = ""; | ||
if (value.length) { | ||
suffix = "..."; | ||
} | ||
return value.slice(0, 20) + suffix; | ||
}) | ||
var plural = (processed.length > 1 ? 's' : ''); | ||
errorMsg = 'the key' + plural + ' (' + processed + ') ' + verb + ' not allowed'; | ||
errorMsg = 'the key' + plural + ' (' + processed + ') ' + verb + ' not allowed (values: ' + processedValues + ')'; | ||
} | ||
@@ -82,0 +106,0 @@ |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": "Van Nguyen <the.gol.effect@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors":[ |
@@ -1,107 +0,132 @@ | ||
var Types = require("../../lib/types/"); | ||
var Types = process.env.TEST_COV ? require('../../lib-cov/types') : require('../../lib/types'); | ||
var verifyBehavior = require("../support/meta").verifyValidatorBehavior; | ||
var should = require("should"); | ||
var verifyBehavior = require("../support/meta").verifyValidatorBehavior; | ||
describe("tests/types/array.js", function(){ | ||
describe("Types.Array", function(){ | ||
var A = Types.Array, | ||
N = Types.Number, | ||
S = Types.String; | ||
describe("#validate", function(){ | ||
it('should work', function(done){ | ||
(function(){ | ||
var arr = A(); | ||
var result = arr.validate([1]); | ||
}).should.not.throw(); | ||
done(); | ||
}) | ||
it('should, by default, allow undefined, allow empty array', function(done){ | ||
verifyBehavior(A(), [ | ||
[undefined, true], | ||
[[], true] | ||
], done); | ||
}) | ||
it("should, when .required(), deny undefined", function(done){ | ||
verifyBehavior(A().required(), [ | ||
[undefined, false] | ||
], done); | ||
}) | ||
it("should validate array of Numbers", function(done){ | ||
verifyBehavior(A().includes(N()), [ | ||
[[1,2,3], true], | ||
[[50, 100, 1000], true], | ||
[["a", 1, 2], false] | ||
], done); | ||
}) | ||
it("should validate array of mixed Numbers & Strings", function(done){ | ||
verifyBehavior(A().includes(N(), S()), [ | ||
[[1,2,3], true], | ||
[[50, 100, 1000], true], | ||
[[1, "a", 5, 10], true], | ||
[["walmart", "everydaylowprices", 5000], true] | ||
], done); | ||
}) | ||
it("should not validate array of unallowed mixed types (Array)", function(done){ | ||
verifyBehavior(A().includes(N()), [ | ||
[[1,2,3], true], | ||
[[1, 2, [1]], false] | ||
], done) | ||
}) | ||
}) | ||
describe("tests/types/array.js", function () { | ||
describe("#_exclude", function(){ | ||
it("should work", function(done){ | ||
var validator = A()._excludes(N()); | ||
var n = [1,2,"hippo"]; | ||
var result = validator(n); | ||
result.should.equal(false); | ||
var m = ['x', 'y', 'z']; | ||
var result2 = validator(m); | ||
result2.should.equal(true); | ||
done(); | ||
// var validator = A()._includes(N()) | ||
// var val2 = A()._includes(S()) | ||
// // var n = [1,2,"hippo"]; | ||
// var n = [[1],[2],[3]]; | ||
// var result = validator(n); | ||
// var result2 = val2(n) | ||
// console.log(result, result2); | ||
// done(); | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe("Types.Array", function () { | ||
var A = Types.Array, | ||
N = Types.Number, | ||
S = Types.String; | ||
it("should have mixins", function (done) { | ||
var result = A(); | ||
should.exist(result.validate); | ||
done(); | ||
}); | ||
describe("#validate", function () { | ||
it('should work', function (done) { | ||
(function () { | ||
var arr = A(); | ||
var result = arr.validate([1]); | ||
}).should.not.throw(); | ||
done(); | ||
}); | ||
it('should, by default, allow undefined, allow empty array', function (done) { | ||
verifyBehavior(A(), [ | ||
[undefined, true], | ||
[ | ||
[], | ||
true | ||
] | ||
], done); | ||
}); | ||
it("should, when .required(), deny undefined", function (done) { | ||
verifyBehavior(A().required(), [ | ||
[undefined, false] | ||
], done); | ||
}); | ||
it("should validate array of Numbers", function (done) { | ||
verifyBehavior(A().includes(N()), [ | ||
[ | ||
[1, 2, 3], | ||
true | ||
], | ||
[ | ||
[50, 100, 1000], | ||
true | ||
], | ||
[ | ||
["a", 1, 2], | ||
false | ||
] | ||
], done); | ||
}); | ||
it("should validate array of mixed Numbers & Strings", function (done) { | ||
verifyBehavior(A().includes(N(), S()), [ | ||
[ | ||
[1, 2, 3], | ||
true | ||
], | ||
[ | ||
[50, 100, 1000], | ||
true | ||
], | ||
[ | ||
[1, "a", 5, 10], | ||
true | ||
], | ||
[ | ||
["walmart", "everydaylowprices", 5000], | ||
true | ||
] | ||
], done); | ||
}); | ||
it("should not validate array of unallowed mixed types (Array)", function (done) { | ||
verifyBehavior(A().includes(N()), [ | ||
[ | ||
[1, 2, 3], | ||
true | ||
], | ||
[ | ||
[1, 2, [1]], | ||
false | ||
] | ||
], done); | ||
}); | ||
}); | ||
describe("#_exclude", function () { | ||
it("should work", function (done) { | ||
var validator = A()._excludes(N()); | ||
var n = [1, 2, "hippo"]; | ||
var result = validator(n); | ||
result.should.equal(false); | ||
var m = ['x', 'y', 'z']; | ||
var result2 = validator(m); | ||
result2.should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
// describe("Types.Array", function(){ | ||
// var A = Types.Array; | ||
// var N = Types.Number; | ||
// // it('should instantiate separate copies on invocation', function(done){ | ||
// // var result1 = A().required(); | ||
// // var result2 = A(); | ||
// // Object.keys(result1).should.not.equal(Object.keys(result2)); | ||
// // done(); | ||
// // }) | ||
// it("should inherit functions from BaseType", function(done){ | ||
// var fns = ["required", "add"]; | ||
// for(var i in fns){ | ||
@@ -112,3 +137,3 @@ // should.exist(A()[fns[i]]); | ||
// }) | ||
// it("should show resulting object with #valueOf", function(done){ | ||
@@ -119,3 +144,3 @@ // var result = A(); | ||
// }) | ||
// describe("#includes", function(done){ | ||
@@ -127,3 +152,3 @@ // it('should exist', function(done){ | ||
// }) | ||
// describe("#_includes", function(done){ | ||
@@ -133,3 +158,3 @@ // it('should validate on known good input', function(done){ | ||
// var validators = A()._includes(N().min(5)); | ||
// for(var j in validators) { | ||
@@ -142,3 +167,3 @@ // var result = validators[j](input); | ||
// }) | ||
// it('should invalidate on known bad input', function(done){ | ||
@@ -149,3 +174,3 @@ // var input = [3, 1]; | ||
// var isValid = true; | ||
// for(var j in validators) { | ||
@@ -159,3 +184,3 @@ // var result = validators[j](input); | ||
// }) | ||
// // describe("#_excludes", function(done){ | ||
@@ -165,3 +190,3 @@ // // it('should validate on known good input', function(done){ | ||
// // var validators = A()._excludes(N().min(5)); | ||
// // for(var j in validators) { | ||
@@ -174,3 +199,3 @@ // // var result = validators[j](input); | ||
// // }) | ||
// // it('should invalidate on known bad input', function(done){ | ||
@@ -181,3 +206,3 @@ // // var input = [10, 20]; | ||
// // var isValid = true; | ||
// // for(var j in validators) { | ||
@@ -191,3 +216,3 @@ // // var result = validators[j](input); | ||
// // }) | ||
// }); |
var should = require("should"); | ||
var Types = require("../../lib/types"); | ||
var Types = process.env.TEST_COV ? require('../../lib-cov/types') : require('../../lib/types'); | ||
var BaseType = Types.Base; | ||
@@ -8,11 +8,11 @@ var Utils = require("../../lib/utils"); | ||
describe("types/base.js", function(){ | ||
describe("BaseType", function(){ | ||
it('should', function(done){ | ||
var B = new BaseType(); | ||
var r = B.allow(undefined); | ||
// console.log("after allow", r); | ||
done(); | ||
describe("types/base.js", function () { | ||
describe("BaseType", function () { | ||
it('should', function (done) { | ||
var B = new BaseType(); | ||
var r = B.allow(undefined); | ||
// console.log("after allow", r); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -29,3 +29,3 @@ | ||
// }) | ||
// it('should return true if null input is given and allowNull is true', function(done){ | ||
@@ -38,3 +38,3 @@ // var base = new BaseType(); | ||
// }) | ||
// it('should return false if null input is given and allowNull is false', function(done){ | ||
@@ -47,3 +47,3 @@ // var base = new BaseType(); | ||
// }) | ||
// it('should return false if no input is given and allowNull is false', function(done){ | ||
@@ -57,3 +57,3 @@ // var base = new BaseType(); | ||
// }) | ||
// describe("#_rename", function(){ | ||
@@ -66,3 +66,3 @@ // var key = "name"; | ||
// var value2 = qstr[key2]; | ||
// it("should alias a variable with default options", function(done){ | ||
@@ -73,3 +73,3 @@ // var base = new BaseType(); | ||
// var result = validator(value, q, key); | ||
// should.exist(q[key3]); | ||
@@ -79,3 +79,3 @@ // q[key3].should.equal(value); | ||
// }) | ||
// it("should move variable if deleteOrig set", function(done){ | ||
@@ -86,3 +86,3 @@ // var base = new BaseType(); | ||
// var result = validator(value, q, key); | ||
// should.exist(q[key3]); | ||
@@ -93,3 +93,3 @@ // should.not.exist(q[key]); | ||
// }) | ||
// it("should overwrite existing variable if allowOverwrite set", function(done){ | ||
@@ -101,3 +101,3 @@ // var base = new BaseType(); | ||
// var result = validator(value, q, key) | ||
// should.exist(q[key2]); | ||
@@ -108,3 +108,3 @@ // q[key2].should.equal(value); | ||
// }) | ||
// it("should not overwrite existing variable if allowOverwrite not set", function(done){ | ||
@@ -115,6 +115,6 @@ // var base = new BaseType(); | ||
// var result = validator(value, q, key); | ||
// should.exist(result); | ||
// result.should.equal(false); | ||
// should.exist(q[key2]); | ||
@@ -125,3 +125,3 @@ // q[key2].should.equal(value2); | ||
// }) | ||
// it("should not allow two renames to set the same key if allowMult not set", function(done){ | ||
@@ -132,8 +132,8 @@ // var base = new BaseType(); | ||
// var result = validator(value, q, key); | ||
// var validator = base._rename(key3, {allowMult: false}) | ||
// var result = validator(value2, q, key2); | ||
// result.should.equal(false); | ||
// // first _rename will not be rolled back | ||
@@ -158,3 +158,3 @@ // should.exist(q[key3]); | ||
// }) | ||
// it('should return error if description is not a string', function(done){ | ||
@@ -172,3 +172,3 @@ // var value = 1; | ||
// }) | ||
// describe("#notes", function(){ | ||
@@ -186,3 +186,3 @@ // it('should set notes if given as string', function(done){ | ||
// }) | ||
// it('should set notes if given as array', function(done){ | ||
@@ -199,3 +199,3 @@ // var value = ["walmart", "@walmartlabs"]; | ||
// }) | ||
// it('should return error if not given as string or array', function(done){ | ||
@@ -211,3 +211,3 @@ // var value = 1; | ||
// }) | ||
// describe("#tags", function(){ | ||
@@ -225,3 +225,3 @@ // it('should set tags if given as array', function(done){ | ||
// }) | ||
// it('should return error if not given as array', function(done){ | ||
@@ -228,0 +228,0 @@ // var value = 1; |
@@ -1,24 +0,36 @@ | ||
var Types = require("../../lib/types"); | ||
var Types = process.env.TEST_COV ? require('../../lib-cov/types') : require('../../lib/types'); | ||
var should = require("should"); | ||
describe("Types", function(){ | ||
// it("should have preset JS types as keys", function(done){ | ||
// var presets = ["String", "Number", "Boolean", "Array", "Object", "Function"]; | ||
// for(var i in presets){ | ||
// should.exist(Types[presets[i]]); | ||
// } | ||
// done(); | ||
// }); | ||
// it("should have preset utility JS types as keys", function(done){ | ||
// var presets = ["Int", "Float", "Date", "Email"]; | ||
// for(var i in presets){ | ||
// should.exist(Types[presets[i]]); | ||
// } | ||
// done(); | ||
// }); | ||
describe("Types", function () { | ||
it("should have a String key", function(done) { | ||
Types.String.should.exist; | ||
done(); | ||
}); | ||
it("should have a Number key", function(done) { | ||
Types.Number.should.exist; | ||
done(); | ||
}); | ||
it("should have a Boolean key", function(done) { | ||
Types.Boolean.should.exist; | ||
done(); | ||
}); | ||
it("should have an Array key", function(done) { | ||
Types.Array.should.exist; | ||
done(); | ||
}); | ||
describe("#validate", function() { | ||
it("should validate a string value on an object", function(done) { | ||
var object = { | ||
testme: "valid" | ||
}; | ||
var validator = function() { return true; }; | ||
Types.validate("testme", "String", object, validator).should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -1,156 +0,149 @@ | ||
var Types = require("../../lib/types/"); | ||
var Types = process.env.TEST_COV ? require('../../lib-cov/types') : require('../../lib/types'); | ||
var should = require("should"); | ||
var verifyBehavior = require("../support/meta").verifyValidatorBehavior; | ||
describe("test/types/number.js", function(){ | ||
describe("Types.Number", function(){ | ||
describe("test/types/number.js", function () { | ||
describe("Types.Number", function () { | ||
var N = Types.Number; | ||
it("should have mixins", function (done) { | ||
var result = N(); | ||
should.exist(result.validate); | ||
done(); | ||
}); | ||
describe("#validate", function () { | ||
it('should work', function (done) { | ||
(function () { | ||
var num = N(); | ||
var result = num.validate(100); | ||
}).should.not.throw(); | ||
done(); | ||
}); | ||
it('should, by default, allow undefined', function (done) { | ||
verifyBehavior(N(), [ | ||
[undefined, true] | ||
], done); | ||
}); | ||
it("should, when .required(), deny undefined", function (done) { | ||
verifyBehavior(N().required(), [ | ||
[undefined, false] | ||
], done); | ||
}); | ||
it("should return false for denied value", function (done) { | ||
var text = N().deny(50); | ||
var result = text.validate(50); | ||
should.exist(result); | ||
result.should.equal(false); | ||
done(); | ||
}); | ||
}) | ||
}) | ||
}) | ||
describe("Types.Number", function () { | ||
var N = Types.Number; | ||
describe("#validate", function(){ | ||
it('should work', function(done){ | ||
(function(){ | ||
var num = N(); | ||
var result = num.validate(100); | ||
}).should.not.throw(); | ||
it('should instantiate separate copies on invocation', function (done) { | ||
var result1 = N().min(5); | ||
var result2 = N().max(5); | ||
Object.keys(result1).should.not.equal(Object.keys(result2)); | ||
done(); | ||
}) | ||
it('should, by default, allow undefined', function(done){ | ||
verifyBehavior(N(), [ | ||
[undefined, true] | ||
], done); | ||
}) | ||
it("should, when .required(), deny undefined", function(done){ | ||
verifyBehavior(N().required(), [ | ||
[undefined, false] | ||
], done); | ||
}) | ||
it("should return false for denied value", function(done){ | ||
var text = N().deny(50); | ||
var result = text.validate(50); | ||
should.exist(result); | ||
result.should.equal(false); | ||
}) | ||
it("should inherit functions from BaseType", function (done) { | ||
var fns = ["required", "add"]; | ||
for (var i in fns) { | ||
should.exist(N()[fns[i]]); | ||
} | ||
done(); | ||
}) | ||
}) | ||
}) | ||
}) | ||
// describe("Types.Number", function(){ | ||
// var N = Types.Number; | ||
// it('should instantiate separate copies on invocation', function(done){ | ||
// var result1 = N().min(5); | ||
// var result2 = N().max(5); | ||
// Object.keys(result1).should.not.equal(Object.keys(result2)); | ||
// done(); | ||
// }) | ||
// it("should inherit functions from BaseType", function(done){ | ||
// var fns = ["required", "add"]; | ||
// for(var i in fns){ | ||
// should.exist(N()[fns[i]]); | ||
// } | ||
// done(); | ||
// }) | ||
// it("should show resulting object with #valueOf", function(done){ | ||
// var result = N().min(5); | ||
// should.exist(result.valueOf()); | ||
// done(); | ||
// }) | ||
// describe("#min", function(done){ | ||
// it('should exist', function(done){ | ||
// should.exist(N().min); | ||
// done(); | ||
// }) | ||
// it("should have corresponding validator function", function(done){ | ||
// should.exist(N()._min); | ||
// done(); | ||
// }) | ||
// it('should have value on #valueOf', function(done){ | ||
// var result = N().min(5).valueOf(); | ||
// should.exist(result); | ||
// (result.length).should.equal(2) | ||
// done(); | ||
// }) | ||
// }) | ||
// describe("#_min", function(done){ | ||
// it('should validate on known valid input', function(done){ | ||
// // var inputs = ["abcde", "fghij", "klmnopqrstuv"]; | ||
// var inputs = [5, 6, 7, 8, 9]; | ||
// var validator = N()._min(5); | ||
// for(var i in inputs){ | ||
// var currentResult = validator(inputs[i]); | ||
// should.exist(currentResult); | ||
// currentResult.should.equal(true); | ||
// } | ||
// done(); | ||
// }) | ||
// it('should invalidate on known invalid inputs', function(done){ | ||
// // var inputs = ["abc", "de", ""]; | ||
// var inputs = [0, 1, 2, 3, 4]; | ||
// var validator = N()._min(5); | ||
// for(var i in inputs){ | ||
// var currentResult = validator(inputs[i]); | ||
// should.exist(currentResult); | ||
// currentResult.should.equal(false); | ||
// } | ||
// done(); | ||
// }) | ||
// }) | ||
// describe("#max", function(done){ | ||
// it('should exist', function(done){ | ||
// should.exist(N().max); | ||
// done(); | ||
// }) | ||
// it("should have corresponding validator function", function(done){ | ||
// should.exist(N()._max); | ||
// done(); | ||
// }) | ||
// it('should have correct length on #valueOf', function(done){ | ||
// var result = N().max(5).valueOf(); | ||
// should.exist(result); | ||
// (result.length).should.equal(2) | ||
// done(); | ||
// }) | ||
// }) | ||
// describe("#_max", function(done){ | ||
// it('should validate on known valid input', function(done){ | ||
// // var inputs = ["abc", "de", ""]; | ||
// var inputs = [0, 1, 2, 3, 4]; | ||
// var validator = N()._max(4); | ||
// for(var i in inputs){ | ||
// var currentResult = validator(inputs[i]); | ||
// should.exist(currentResult); | ||
// currentResult.should.equal(true); | ||
// } | ||
// done(); | ||
// }) | ||
// it('should invalidate on known invalid inputs', function(done){ | ||
// // var inputs = ["abcde", "fghij", "klmnopqrstuv"]; | ||
// var inputs = [5, 6, 7, 8]; | ||
// var validator = N()._max(4); | ||
// for(var i in inputs){ | ||
// var currentResult = validator(inputs[i]); | ||
// should.exist(currentResult); | ||
// currentResult.should.equal(false); | ||
// } | ||
// done(); | ||
// }) | ||
// }) | ||
// }) | ||
it("should show resulting object with #valueOf", function (done) { | ||
var result = N().min(5); | ||
should.exist(result.valueOf()); | ||
done(); | ||
}) | ||
describe("#min", function (done) { | ||
it('should exist', function (done) { | ||
should.exist(N().min); | ||
done(); | ||
}); | ||
it("should have corresponding validator function", function (done) { | ||
should.exist(N()._min); | ||
done(); | ||
}); | ||
}) | ||
describe("#_min", function (done) { | ||
it('should validate on known valid input', function (done) { | ||
// var inputs = ["abcde", "fghij", "klmnopqrstuv"]; | ||
var inputs = [5, 6, 7, 8, 9]; | ||
var validator = N()._min(5); | ||
for (var i in inputs) { | ||
var currentResult = validator(inputs[i]); | ||
should.exist(currentResult); | ||
currentResult.should.equal(true); | ||
} | ||
done(); | ||
}) | ||
it('should invalidate on known invalid inputs', function (done) { | ||
// var inputs = ["abc", "de", ""]; | ||
var inputs = [0, 1, 2, 3, 4]; | ||
var validator = N()._min(5); | ||
for (var i in inputs) { | ||
var currentResult = validator(inputs[i]); | ||
should.exist(currentResult); | ||
currentResult.should.equal(false); | ||
} | ||
done(); | ||
}) | ||
}) | ||
describe("#max", function (done) { | ||
it('should exist', function (done) { | ||
should.exist(N().max); | ||
done(); | ||
}); | ||
it("should have corresponding validator function", function (done) { | ||
should.exist(N()._max); | ||
done(); | ||
}); | ||
}); | ||
describe("#_max", function (done) { | ||
it('should validate on known valid input', function (done) { | ||
// var inputs = ["abc", "de", ""]; | ||
var inputs = [0, 1, 2, 3, 4]; | ||
var validator = N()._max(4); | ||
for (var i in inputs) { | ||
var currentResult = validator(inputs[i]); | ||
should.exist(currentResult); | ||
currentResult.should.equal(true); | ||
} | ||
done(); | ||
}) | ||
it('should invalidate on known invalid inputs', function (done) { | ||
// var inputs = ["abcde", "fghij", "klmnopqrstuv"]; | ||
var inputs = [5, 6, 7, 8]; | ||
var validator = N()._max(4); | ||
for (var i in inputs) { | ||
var currentResult = validator(inputs[i]); | ||
should.exist(currentResult); | ||
currentResult.should.equal(false); | ||
} | ||
done(); | ||
}) | ||
}) | ||
}) |
@@ -1,2 +0,2 @@ | ||
var Types = require("../../lib/types/"); | ||
var Types = process.env.TEST_COV ? require('../../lib-cov/types') : require('../../lib/types'); | ||
var should = require("should"); | ||
@@ -6,138 +6,145 @@ var verifyBehavior = require("../support/meta").verifyValidatorBehavior; | ||
describe("test/types/string.js", function(){ | ||
describe("Types.String", function(){ | ||
var S = Types.String; | ||
it("should instantiate separate copies on invocation", function(done){ | ||
var result1 = S().min(5); | ||
var result2 = S().max(5); | ||
Object.keys(result1).should.not.equal(Object.keys(result2)); | ||
done(); | ||
}) | ||
describe("#valid", function(){ | ||
it("should throw error on input not matching type", function(done){ | ||
(function(){ | ||
S().valid(1); | ||
}).should.throw(); | ||
done() | ||
}) | ||
it("should not throw on input matching type", function(done){ | ||
(function(){ | ||
S().valid("walmart"); | ||
}).should.not.throw(); | ||
done() | ||
}) | ||
}) | ||
describe("#invalid", function(){ | ||
it("should throw error on input not matching type", function(done){ | ||
(function(){ | ||
S().invalid(1); | ||
}).should.throw(); | ||
done() | ||
}) | ||
it("should not throw on input matching type", function(done){ | ||
(function(){ | ||
S().invalid("walmart"); | ||
}).should.not.throw(); | ||
done() | ||
}) | ||
}) | ||
describe("#validate", function(){ | ||
it('should work', function(done){ | ||
(function(){ | ||
var text = S(); | ||
var result = text.validate("joi"); | ||
}).should.not.throw(); | ||
done(); | ||
}) | ||
it('should, by default, allow undefined, deny empty string', function(done){ | ||
var conditions = [ | ||
[undefined, true], | ||
["", false] | ||
]; | ||
verifyBehavior(S(), conditions, done); | ||
}) | ||
it("should, when .required(), deny undefined, deny empty string", function(done){ | ||
var t = S().required(); | ||
verifyBehavior(t, [ | ||
[undefined, false], | ||
["", false] | ||
], done); | ||
}) | ||
it("should return false for denied value", function(done){ | ||
var text = S().deny("joi"); | ||
var result = text.validate("joi"); | ||
should.exist(result); | ||
result.should.equal(false); | ||
done(); | ||
}) | ||
it("should return true for allowed value", function(done){ | ||
var text = S().allow("hapi"); | ||
var result = text.validate("result"); | ||
should.exist(result); | ||
result.should.equal(true); | ||
done(); | ||
}) | ||
it("should validate with one validator (min)", function(done){ | ||
var text = S().min(3); | ||
var result = text.validate("walmart"); | ||
should.exist(result); | ||
result.should.equal(true); | ||
done(); | ||
}) | ||
it("should validate with two validators (min, required)", function(done){ | ||
var text = S().min(3).required(); | ||
var result = text.validate("walmart") | ||
should.exist(result); | ||
result.should.equal(true); | ||
var result2 = text.validate(); | ||
should.exist(result2); | ||
result2.should.equal(false); | ||
done(); | ||
}) | ||
it("should validate null with nullOk()", function(done){ | ||
verifyBehavior(S().nullOk(), [ | ||
[null, true] | ||
], done); | ||
}) | ||
it("should validate '' (empty string) with emptyOk()", function(done){ | ||
verifyBehavior(S().emptyOk(), [ | ||
['', true], | ||
["", true] | ||
], done); | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe("test/types/string.js", function () { | ||
describe("Types.String", function () { | ||
var S = Types.String; | ||
it("should have mixins", function (done) { | ||
var result = S(); | ||
should.exist(result.validate); | ||
done(); | ||
}); | ||
it("should instantiate separate copies on invocation", function (done) { | ||
var result1 = S().min(5); | ||
var result2 = S().max(5); | ||
Object.keys(result1).should.not.equal(Object.keys(result2)); | ||
done(); | ||
}); | ||
describe("#valid", function () { | ||
it("should throw error on input not matching type", function (done) { | ||
(function () { | ||
S().valid(1); | ||
}).should.throw(); | ||
done(); | ||
}); | ||
it("should not throw on input matching type", function (done) { | ||
(function () { | ||
S().valid("walmart"); | ||
}).should.not.throw(); | ||
done(); | ||
}); | ||
}); | ||
describe("#invalid", function () { | ||
it("should throw error on input not matching type", function (done) { | ||
(function () { | ||
S().invalid(1); | ||
}).should.throw(); | ||
done(); | ||
}); | ||
it("should not throw on input matching type", function (done) { | ||
(function () { | ||
S().invalid("walmart"); | ||
}).should.not.throw(); | ||
done(); | ||
}); | ||
}); | ||
describe("#validate", function () { | ||
it('should work', function (done) { | ||
(function () { | ||
var text = S(); | ||
var result = text.validate("joi"); | ||
}).should.not.throw(); | ||
done(); | ||
}); | ||
it('should, by default, allow undefined, deny empty string', function (done) { | ||
var conditions = [ | ||
[undefined, true], | ||
["", false] | ||
]; | ||
verifyBehavior(S(), conditions, done); | ||
}); | ||
it("should, when .required(), deny undefined, deny empty string", function (done) { | ||
var t = S().required(); | ||
verifyBehavior(t, [ | ||
[undefined, false], | ||
["", false] | ||
], done); | ||
}); | ||
it("should return false for denied value", function (done) { | ||
var text = S().deny("joi"); | ||
var result = text.validate("joi"); | ||
should.exist(result); | ||
result.should.equal(false); | ||
done(); | ||
}); | ||
it("should return true for allowed value", function (done) { | ||
var text = S().allow("hapi"); | ||
var result = text.validate("result"); | ||
should.exist(result); | ||
result.should.equal(true); | ||
done(); | ||
}); | ||
it("should validate with one validator (min)", function (done) { | ||
var text = S().min(3); | ||
var result = text.validate("walmart"); | ||
should.exist(result); | ||
result.should.equal(true); | ||
done(); | ||
}); | ||
it("should validate with two validators (min, required)", function (done) { | ||
var text = S().min(3).required(); | ||
var result = text.validate("walmart") | ||
should.exist(result); | ||
result.should.equal(true); | ||
var result2 = text.validate(); | ||
should.exist(result2); | ||
result2.should.equal(false); | ||
done(); | ||
}); | ||
it("should validate null with nullOk()", function (done) { | ||
verifyBehavior(S().nullOk(), [ | ||
[null, true] | ||
], done); | ||
}); | ||
it("should validate '' (empty string) with emptyOk()", function (done) { | ||
verifyBehavior(S().emptyOk(), [ | ||
['', true], | ||
["", true] | ||
], done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
// describe("Types.String", function(){ | ||
// var S = Types.String; | ||
// it('should instantiate separate copies on invocation', function(done){ | ||
// var result1 = S().min(5); | ||
// var result2 = S().max(5); | ||
// Object.keys(result1).should.not.equal(Object.keys(result2)); | ||
// done(); | ||
// }) | ||
// it("should inherit functions from BaseType", function(done){ | ||
// var fns = ["required", "add"]; | ||
// for(var i in fns){ | ||
@@ -148,3 +155,3 @@ // should.exist(S()[fns[i]]); | ||
// }) | ||
// it("should show resulting object with #valueOf", function(done){ | ||
@@ -155,3 +162,3 @@ // var result = S().min(5); | ||
// }) | ||
// // describe("#_base", function(){ | ||
@@ -165,3 +172,3 @@ // // it("should work", function(done){ | ||
// // }) | ||
// describe("#min", function(done){ | ||
@@ -172,3 +179,3 @@ // it('should exist', function(done){ | ||
// }) | ||
// it("should have corresponding validator function", function(done){ | ||
@@ -178,3 +185,3 @@ // should.exist(S()._min); | ||
// }) | ||
// it('should have value on #valueOf', function(done){ | ||
@@ -187,3 +194,3 @@ // var result = S().min(5).valueOf(); | ||
// }) | ||
// describe("#_min", function(done){ | ||
@@ -200,3 +207,3 @@ // it('should validate on known valid input', function(done){ | ||
// }) | ||
// it('should invalidate on known invalid inputs', function(done){ | ||
@@ -213,3 +220,3 @@ // var inputs = ["abc", "de", ""]; | ||
// }) | ||
// describe("#max", function(done){ | ||
@@ -220,3 +227,3 @@ // it('should exist', function(done){ | ||
// }) | ||
// it("should have corresponding validator function", function(done){ | ||
@@ -226,3 +233,3 @@ // should.exist(S()._max); | ||
// }) | ||
// it('should have correct length on #valueOf', function(done){ | ||
@@ -235,3 +242,3 @@ // var result = S().max(5).valueOf(); | ||
// }) | ||
// describe("#_max", function(done){ | ||
@@ -248,3 +255,3 @@ // it('should validate on known valid input', function(done){ | ||
// }) | ||
// it('should invalidate on known invalid inputs', function(done){ | ||
@@ -261,3 +268,3 @@ // var inputs = ["abcde", "fghij", "klmnopqrstuv"]; | ||
// }) | ||
// describe("#regex", function(done){ | ||
@@ -268,3 +275,3 @@ // it('should exist', function(done){ | ||
// }) | ||
// it("should have corresponding validator function", function(done){ | ||
@@ -274,3 +281,3 @@ // should.exist(S()._regex); | ||
// }) | ||
// it('should have correct length on #valueOf', function(done){ | ||
@@ -283,3 +290,3 @@ // var result = S().regex(/^[a-z]+$/).valueOf(); | ||
// }) | ||
// describe("#_regex", function(done){ | ||
@@ -296,3 +303,3 @@ // it('should validate on known valid input', function(done){ | ||
// }) | ||
// it('should invalidate on known invalid inputs', function(done){ | ||
@@ -299,0 +306,0 @@ // var inputs = ["abcd#f?h1j", "m3ch4", "m3g4"]; |
@@ -1,34 +0,34 @@ | ||
var Utils = require("../lib/utils"); | ||
var Utils = process.env.TEST_COV ? require('../lib-cov/utils') : require('../lib/utils'); | ||
var should = require("should"); | ||
describe("test/utils.js", function(){ | ||
describe("Utils", function(){ | ||
describe("Set", function(){ | ||
var Set = Utils.Set; | ||
it('should work with numbers', function(done){ | ||
var s = new Set(); | ||
s.add(1) | ||
s.add(2) | ||
s.get().length.should.equal(2) | ||
s.remove(2); | ||
s.get().length.should.equal(1) | ||
done(); | ||
}) | ||
it('should work with undefined', function(done){ | ||
var s = new Set(); | ||
s.add(undefined) | ||
s.has(undefined).should.equal(true); | ||
done(); | ||
}) | ||
it('should work with arrays', function(done){ | ||
var s = new Set(); | ||
s.add([1,2,3]) | ||
s.has([1,2,3]).should.equal(true); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe("test/utils.js", function () { | ||
describe("Utils", function () { | ||
describe("Set", function () { | ||
var Set = Utils.Set; | ||
it('should work with numbers', function (done) { | ||
var s = new Set(); | ||
s.add(1); | ||
s.add(2); | ||
s.get().length.should.equal(2); | ||
s.remove(2); | ||
s.get().length.should.equal(1); | ||
done(); | ||
}) | ||
it('should work with undefined', function (done) { | ||
var s = new Set(); | ||
s.add(undefined) | ||
s.has(undefined).should.equal(true); | ||
done(); | ||
}) | ||
it('should work with arrays', function (done) { | ||
var s = new Set(); | ||
s.add([1, 2, 3]); | ||
s.has([1, 2, 3]).should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
65969
25
1786
8