piggy-proof
Advanced tools
Comparing version 0.0.12 to 0.0.13
{ | ||
"name": "piggy-proof", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Validate an object of properties meets given validation rules", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,7 +0,9 @@ | ||
var addresses = { | ||
line1: ['isPresent'], | ||
zipOrPostcode: ['isPresent'], | ||
country: ['isPresent'] | ||
}; | ||
var addresses = function() { | ||
return Object.freeze({ | ||
line1: ['isPresent'], | ||
zipOrPostcode: ['isPresent'], | ||
country: ['isPresent'] | ||
}); | ||
} | ||
module.exports = addresses; |
@@ -1,12 +0,14 @@ | ||
var cards = { | ||
expiry: ['isPresent', 'isCardExpiryFormat'], | ||
shortDescription: ['isPresent'], | ||
longDescription: ['isPresent'], | ||
retired: ['isBoolean'], | ||
imageLarge: ['isPresent'], | ||
imageMedium: ['isPresent'], | ||
imageSmall: ['isPresent'], | ||
digitalDelivery: ['isBoolean'] | ||
}; | ||
var cards = function() { | ||
return Object.freeze({ | ||
expiry: ['isPresent', 'isCardExpiryFormat'], | ||
shortDescription: ['isPresent'], | ||
longDescription: ['isPresent'], | ||
retired: ['isBoolean'], | ||
imageLarge: ['isPresent'], | ||
imageMedium: ['isPresent'], | ||
imageSmall: ['isPresent'], | ||
digitalDelivery: ['isBoolean'] | ||
}); | ||
} | ||
module.exports = cards; |
@@ -1,14 +0,16 @@ | ||
var pots = { | ||
title: ['isPresent'], | ||
savingsTarget: ['isPresent', 'isNumber'], | ||
dateTarget: ['isDate'], | ||
depositStartDate: ['isDate'], | ||
longDescription: ['isPresent'], | ||
retired: ['isBoolean'], | ||
imageLarge: ['isPresent'], | ||
imageMedium: ['isPresent'], | ||
imageSmall: ['isPresent'], | ||
digitalDelivery: ['isBoolean'] | ||
}; | ||
var pots = function() { | ||
return Object.freeze({ | ||
title: ['isPresent'], | ||
savingsTarget: ['isPresent', 'isNumber'], | ||
dateTarget: ['isDate'], | ||
depositStartDate: ['isDate'], | ||
longDescription: ['isPresent'], | ||
retired: ['isBoolean'], | ||
imageLarge: ['isPresent'], | ||
imageMedium: ['isPresent'], | ||
imageSmall: ['isPresent'], | ||
digitalDelivery: ['isBoolean'] | ||
}); | ||
} | ||
module.exports = pots; |
@@ -1,14 +0,16 @@ | ||
var skus = { | ||
name: ['isPresent'], | ||
shortDescription: ['isPresent'], | ||
longDescription: ['isPresent'], | ||
retired: ['isBoolean'], | ||
imageLarge: ['isPresent'], | ||
imageMedium: ['isPresent'], | ||
imageSmall: ['isPresent'], | ||
digitalDelivery: ['isBoolean'], | ||
availableOnly: ['isDate'], | ||
availableFrom: ['isDate'] | ||
}; | ||
var skus = function() { | ||
return Object.freeze({ | ||
name: ['isPresent'], | ||
shortDescription: ['isPresent'], | ||
longDescription: ['isPresent'], | ||
retired: ['isBoolean'], | ||
imageLarge: ['isPresent'], | ||
imageMedium: ['isPresent'], | ||
imageSmall: ['isPresent'], | ||
digitalDelivery: ['isBoolean'], | ||
availableOnly: ['isDate'], | ||
availableFrom: ['isDate'] | ||
}); | ||
} | ||
module.exports = skus; |
@@ -1,12 +0,14 @@ | ||
var transactions = { | ||
type: ['isPresent'], | ||
recurring: ['isPresent'], | ||
state: ['isPresent', 'isOneOf:COMPLETE,PENDING,ERROR,RESOLVED'], | ||
stateMessage: ['isPresent'], | ||
amount: ['isPresent', 'isNumber'], | ||
currency: ['isPresent'], | ||
scheduledFor: ['isDate'], | ||
processedOn: ['isDate'] | ||
}; | ||
var transactions = function() { | ||
return Object.freeze({ | ||
type: ['isPresent'], | ||
recurring: ['isPresent'], | ||
state: ['isPresent', 'isOneOf:COMPLETE,PENDING,ERROR,RESOLVED'], | ||
stateMessage: ['isPresent'], | ||
amount: ['isPresent', 'isNumber'], | ||
currency: ['isPresent'], | ||
scheduledFor: ['isDate'], | ||
processedOn: ['isDate'] | ||
}); | ||
} | ||
module.exports = transactions; |
@@ -1,10 +0,12 @@ | ||
var users = { | ||
password: ['isPresent', 'minLength:8', 'isPassword'], | ||
firstName: ['isPresent'], | ||
lastName: ['isPresent'], | ||
email: ['isPresent', 'isEmail'], | ||
age: ['isUnsignedInt'], | ||
phone: ['isPresent'] | ||
}; | ||
var users = function() { | ||
return Object.freeze({ | ||
password: ['isPresent', 'minLength:8', 'isPassword'], | ||
firstName: ['isPresent'], | ||
lastName: ['isPresent'], | ||
email: ['isPresent', 'isEmail'], | ||
age: ['isUnsignedInt'], | ||
phone: ['isPresent'] | ||
}); | ||
} | ||
module.exports = users; |
@@ -8,3 +8,3 @@ var RuleParser = require('./rule-parser'); | ||
var validationResults = {}; | ||
var rules = Models[modelName]; | ||
var rules = Object.assign({}, Models[modelName]()); | ||
@@ -11,0 +11,0 @@ // Only validate fields that are supplied if |
@@ -16,3 +16,2 @@ var expect = require('chai').expect; | ||
}; | ||
expect(PiggyProof.validate(data, 'users')).to.deep.equal({ | ||
@@ -22,3 +21,4 @@ password: [ 'is below the minimum length' ], | ||
lastName: [ 'is not present' ], | ||
email: [ 'is not present' ] | ||
email: [ 'is not present' ], | ||
phone: [ 'is not present' ] | ||
}); | ||
@@ -28,2 +28,31 @@ done(); | ||
it('should not modify global object models for all users!!!', function(done) { | ||
var invalidData1 = { | ||
password: 'ab' | ||
}; | ||
var invalidData2 = { | ||
email: 'phil', | ||
password: 'mybigpassword1', | ||
}; | ||
var invalidResults1 = PiggyProof.validate(invalidData1, 'users', true); | ||
expect(PiggyProof.isValid(invalidResults1)).to.be.false; | ||
expect(invalidResults1).to.deep.equal({ | ||
password: [ 'is below the minimum length', 'does not contain any numbers' ] | ||
}); | ||
var invalidResults2 = PiggyProof.validate(invalidData1, 'users', false); | ||
expect(PiggyProof.isValid(invalidResults2)).to.be.false; | ||
expect(invalidResults2).to.deep.equal({ | ||
password: [ 'is below the minimum length', 'does not contain any numbers' ], | ||
firstName: [ 'is not present' ], | ||
lastName: [ 'is not present' ], | ||
email: [ 'is not present' ], | ||
phone: [ 'is not present' ] | ||
}); | ||
done(); | ||
}); | ||
it('should ignore fields that do not exist on the model', function(done) { | ||
@@ -34,3 +63,2 @@ var data = { | ||
}; | ||
expect(PiggyProof.validate(data, 'users')).to.deep.equal({ | ||
@@ -40,3 +68,4 @@ password: [ 'is below the minimum length' ], | ||
lastName: [ 'is not present' ], | ||
email: [ 'is not present' ] | ||
email: [ 'is not present' ], | ||
phone: [ 'is not present' ] | ||
}); | ||
@@ -55,3 +84,4 @@ done(); | ||
lastName: [ 'is not present' ], | ||
email: [ 'is not present' ] | ||
email: [ 'is not present' ], | ||
phone: [ 'is not present' ] | ||
}); | ||
@@ -72,3 +102,4 @@ done(); | ||
lastName: 'Bloggs', | ||
dateOfBirth: '1999-09-09' | ||
dateOfBirth: '1999-09-09', | ||
phone: '07777777777' | ||
}; | ||
@@ -79,2 +110,3 @@ | ||
expect(PiggyProof.isValid(invalidResults)).to.be.false; | ||
@@ -81,0 +113,0 @@ expect(PiggyProof.isValid(validResults)).to.be.true; |
@@ -24,4 +24,6 @@ var expect = require('chai').expect; | ||
var invalidResult = ValidationMethods['isEmail']('ab 1999@aol.co.uk'); | ||
var invalidResult2 = ValidationMethods['isEmail']('ab1999'); | ||
expect(validResult).to.equal(undefined); | ||
expect(invalidResult).to.equal('is not a valid email format'); | ||
expect(invalidResult2).to.equal('is not a valid email format'); | ||
done(); | ||
@@ -28,0 +30,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
17727
467