mongoose-auto-api.validation
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -122,2 +122,24 @@ var assert, should, v; | ||
// JSON Validation | ||
describe('JSON Validation', function() { | ||
var val; | ||
val = v.jsonVal('', 'jsonField'); | ||
it('Returns object', function() { | ||
return val.should.be.a('object'); | ||
}); | ||
it('Messages and Codes Length', function() { | ||
return assert(val.messages.length === val.codes.length); | ||
}); | ||
it('Required Check', function() { | ||
return assert(val.codes.includes('JSON_FIELD_REQUIRED')); | ||
}); | ||
it('Invalid JSON Check', function() { | ||
return assert(val.codes.includes('JSON_FIELD_INVALID_JSON')); | ||
}); | ||
return it('Valid JSON', function() { | ||
val = v.jsonVal('{"a":1,"b":"2","c":[1]}', 'jsonField'); | ||
return assert(val.codes.length === 0 && val.messages.length === 0 && val.valid); | ||
}); | ||
}); | ||
// Join Validations | ||
@@ -124,0 +146,0 @@ describe('Join Validations', function() { |
@@ -1,2 +0,2 @@ | ||
var camelCase, confirmPassVal, confirmValidation, joinValidations, lenValidation, lengthVal, mailValidation, multiValidations, passVal, passValidation, reqValidation, requiredVal, snakeCase, startCase, titleCase, upperSnakeCase, userVal, validationObject; | ||
var camelCase, confirmPassVal, confirmValidation, joinValidations, jsonVal, jsonValidation, lenValidation, lengthVal, mailValidation, multiValidations, passVal, passValidation, reqValidation, requiredVal, snakeCase, startCase, titleCase, upperSnakeCase, userVal, validationObject; | ||
@@ -85,2 +85,14 @@ startCase = require('lodash.startcase'); | ||
//: JSON Validation | ||
jsonVal = function(text, field) { | ||
return multiValidations(text, field, [ | ||
{ | ||
func: reqValidation | ||
}, | ||
{ | ||
func: jsonValidation | ||
} | ||
]); | ||
}; | ||
//: Required Validation | ||
@@ -133,2 +145,18 @@ reqValidation = function(text, args) { | ||
//: JSON Validation | ||
jsonValidation = function(text, args) { | ||
var isValid; | ||
isValid = true; | ||
try { | ||
JSON.parse(text); | ||
} catch (error1) { | ||
isValid = false; | ||
} | ||
if (!isValid) { | ||
return ['must be a valid JSON object', 'INVALID_JSON']; | ||
} else { | ||
return true; | ||
} | ||
}; | ||
//: Validation Object | ||
@@ -180,2 +208,2 @@ validationObject = function(text, field, check, args) { | ||
module.exports = {userVal, passVal, confirmPassVal, requiredVal, lengthVal, joinValidations}; | ||
module.exports = {userVal, passVal, confirmPassVal, jsonVal, requiredVal, lengthVal, joinValidations}; |
{ | ||
"name": "mongoose-auto-api.validation", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Automatic Mongoose REST API - Validations module", | ||
@@ -47,2 +47,2 @@ "main": "./js/index.js", | ||
} | ||
} | ||
} |
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
13561
346