不要怂,就是干,撸起袖子干!

link dao-validations.test file INDENTATIONS

1 parent 678b9267
Showing with 129 additions and 130 deletions
......@@ -199,13 +199,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var failingUser = UserFail.build({ name : failingValue })
failingUser.validate().done( function(err, _errors) {
expect(_errors).to.not.be.null
expect(_errors).to.be.an.instanceOf(Error)
expect(_errors.name[0].message).to.equal(message)
done()
})
})
failingUser.validate().done( function(err, _errors) {
expect(_errors).to.not.be.null
expect(_errors).to.be.an.instanceOf(Error)
expect(_errors.name[0].message).to.equal(message)
done()
})
})
}
, applyPassTest = function applyPassTest(validatorDetails, j, validator) {
var succeedingValue = validatorDetails.pass[j]
......@@ -231,7 +231,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
expect(arguments).to.have.length(0)
done()
}).error(function(err) {
expect(err).to.deep.equal({})
expect(err).to.deep.equal({})
done()
})
})
......@@ -298,14 +298,14 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}
})
Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) {
model.updateAttributes({name: ''}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.name[0].message).to.equal('Validation notEmpty failed');
done()
})
})
Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) {
model.updateAttributes({name: ''}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.name[0].message).to.equal('Validation notEmpty failed');
done()
})
})
})
})
......@@ -318,16 +318,16 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
notEmpty: true // don't allow empty strings
}
}
})
Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function() {
Model.update({name: ''}, {id: 1}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.name[0].message).to.equal('Validation notEmpty failed')
done()
})
})
})
Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function() {
Model.update({name: ''}, {id: 1}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.name[0].message).to.equal('Validation notEmpty failed')
done()
})
})
})
})
})
......@@ -398,13 +398,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}
})
User.sync({ force: true }).success(function() {
User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('Validation isInt failed')
done()
})
})
User.sync({ force: true }).success(function() {
User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('Validation isInt failed')
done()
})
})
})
it('should emit an error when we try to enter in a string for an auto increment key (not named id)', function(done) {
......@@ -419,13 +419,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}
})
User.sync({ force: true }).success(function() {
User.create({username: 'helloworldhelloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.username[0].message).to.equal('Username must be an integer!')
done()
})
})
User.sync({ force: true }).success(function() {
User.create({username: 'helloworldhelloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.username[0].message).to.equal('Username must be an integer!')
done()
})
})
})
describe("primaryKey with the name as id with arguments for it's validation", function() {
......@@ -446,80 +446,80 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
})
})
it('should emit an error when we try to enter in a string for the id key with validation arguments', function(done) {
this.User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!')
done()
})
})
it('should emit an error when we try to enter in a string for the id key with validation arguments', function(done) {
this.User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!')
done()
})
})
it('should emit an error when we try to enter in a string for an auto increment key through .build().validate()', function(done) {
var user = this.User.build({id: 'helloworld'})
user.validate().success(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!')
done()
})
})
it('should emit an error when we try to .save()', function(done) {
var user = this.User.build({id: 'helloworld'})
user.save().error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!')
done()
})
})
})
var user = this.User.build({id: 'helloworld'})
user.validate().success(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!')
done()
})
})
it('should emit an error when we try to .save()', function(done) {
var user = this.User.build({id: 'helloworld'})
user.save().error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(err.id[0].message).to.equal('ID must be an integer!')
done()
})
})
})
})
describe('Pass all paths when validating', function() {
beforeEach(function(done) {
var self = this
var Project = this.sequelize.define('Project', {
name: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isIn: [['unknown', 'hello', 'test']]
}
},
creatorName: {
type: Sequelize.STRING,
allowNull: false,
},
cost: {
type: Sequelize.INTEGER,
allowNull: false,
},
})
var Task = this.sequelize.define('Task', {
something: Sequelize.INTEGER
})
Project.hasOne(Task)
Task.hasOne(Project)
Project.sync({ force: true }).success(function() {
Task.sync({ force: true }).success(function() {
self.Project = Project
self.Task = Task
beforeEach(function(done) {
var self = this
var Project = this.sequelize.define('Project', {
name: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isIn: [['unknown', 'hello', 'test']]
}
},
creatorName: {
type: Sequelize.STRING,
allowNull: false,
},
cost: {
type: Sequelize.INTEGER,
allowNull: false,
},
})
var Task = this.sequelize.define('Task', {
something: Sequelize.INTEGER
})
Project.hasOne(Task)
Task.hasOne(Project)
Project.sync({ force: true }).success(function() {
Task.sync({ force: true }).success(function() {
self.Project = Project
self.Task = Task
done()
})
})
})
it('produce 3 errors', function(done) {
this.Project.create({}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(Object.keys(err)).to.have.length(3)
done()
})
})
it('produce 3 errors', function(done) {
this.Project.create({}).error(function(err) {
expect(err).to.be.an.instanceOf(Error)
expect(Object.keys(err)).to.have.length(3)
done()
})
})
})
})
......@@ -542,16 +542,16 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var failingUser = User.build({ name : "3" })
failingUser.validate().success(function(error) {
expect(error).to.be.an.instanceOf(Error)
expect(error).to.be.an.instanceOf(Error)
expect(error.name[0].message).to.equal("name should equal '2'")
expect(error.name[0].message).to.equal("name should equal '2'")
var successfulUser = User.build({ name : "2" })
successfulUser.validate().success(function() {
expect(arguments).to.have.length(0)
done()
}).error(function(err) {
expect(err[0].message).to.equal()
expect(err[0].message).to.equal()
done()
})
})
......@@ -570,14 +570,14 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.build({ age: -1 })
.validate()
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error)
expect(error.age[0].message).to.equal("must be positive")
User.build({ age: null }).validate().success(function() {
User.build({ age: 1 }).validate().success(function() {
.validate()
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error)
expect(error.age[0].message).to.equal("must be positive")
User.build({ age: null }).validate().success(function() {
User.build({ age: 1 }).validate().success(function() {
done()
})
})
......@@ -608,13 +608,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Foo
.build({ field1: null, field2: null })
.validate()
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error)
expect(error.xnor[0].message).to.equal('xnor failed');
Foo
.validate()
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error)
expect(error.xnor[0].message).to.equal('xnor failed');
Foo
.build({ field1: 33, field2: null })
.validate()
.success(function(errors) {
......@@ -646,13 +645,13 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Foo
.build({ field1: null, field2: null })
.validate()
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error)
expect(error.xnor[0].message).to.equal('xnor failed')
.validate()
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.an.instanceOf(Error)
expect(error.xnor[0].message).to.equal('xnor failed')
Foo
Foo
.build({ field1: 33, field2: null })
.validate()
.success(function(errors) {
......@@ -700,7 +699,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
failingBar.validate().success(function(errors) {
expect(errors).not.to.be.null
expect(errors.field).to.have.length(1)
expect(errors.field[0].message).to.equal("Validation isIn failed")
expect(errors.field[0].message).to.equal("Validation isIn failed")
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!