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

refactor remaining validation tests to support new Error pattern

1 parent 620fb0e3
Showing with 27 additions and 17 deletions
......@@ -306,7 +306,8 @@ 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.deep.equal({ name: [ 'String is empty' ] })
expect(err).to.be.instanceOf(Error)
expect(err.name).to.deep.equal(['String is empty']);
done()
})
})
......@@ -327,7 +328,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model.sync({ force: true }).success(function() {
Model.create({name: 'World'}).success(function(model) {
Model.update({name: ''}, {id: 1}).error(function(err) {
expect(err).to.deep.equal({ name: [ 'String is empty' ] })
expect(err).to.be.instanceOf(Error)
expect(err.name).to.deep.equal(['String is empty']);
done()
})
})
......@@ -405,7 +407,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User.sync({ force: true }).success(function() {
User.create({id: 'helloworld'}).error(function(err) {
expect(err).to.deep.equal({id: ['Invalid integer']})
expect(err).to.be.instanceOf(Error)
expect(err.id).to.deep.equal(['Invalid integer']);
done()
})
})
......@@ -425,7 +428,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User.sync({ force: true }).success(function() {
User.create({username: 'helloworldhelloworld'}).error(function(err) {
expect(err).to.deep.equal({username: ['Username must be an integer!']})
expect(err).to.be.instanceOf(Error)
expect(err.username).to.deep.equal(['Username must be an integer!']);
done()
})
})
......@@ -451,7 +455,8 @@ 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.deep.equal({id: ['ID must be an integer!']})
expect(err).to.be.instanceOf(Error)
expect(err.id).to.deep.equal(['ID must be an integer!']);
done()
})
})
......@@ -459,8 +464,9 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
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(errors) {
expect(errors).to.deep.equal({ id: [ 'ID must be an integer!' ] })
user.validate().success(function(err) {
expect(err).to.be.instanceOf(Error)
expect(err.id).to.deep.equal(['ID must be an integer!']);
done()
})
})
......@@ -468,7 +474,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
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.deep.equal({ id: [ 'ID must be an integer!' ] })
expect(err).to.be.instanceOf(Error)
expect(err.id).to.deep.equal(['ID must be an integer!']);
done()
})
})
......@@ -523,9 +530,10 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.build({ age: -1 })
.validate()
.success(function(errors) {
expect(errors).not.to.be.null
expect(errors).to.deep.equal({ age: ['must be positive'] })
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.instanceOf(Error);
expect(error.age).to.deep.equal(["must be positive"])
User.build({ age: null }).validate().success(function() {
User.build({ age: 1 }).validate().success(function() {
......@@ -560,9 +568,10 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Foo
.build({ field1: null, field2: null })
.validate()
.success(function(errors) {
expect(errors).not.to.be.null
expect(errors).to.deep.equal({ 'xnor': ['xnor failed'] })
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.instanceOf(Error)
expect(error.xnor).to.deep.equal(['xnor failed']);
Foo
.build({ field1: 33, field2: null })
......@@ -597,9 +606,10 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Foo
.build({ field1: null, field2: null })
.validate()
.success(function(errors) {
expect(errors).not.to.be.null
expect(errors).to.deep.equal({ 'xnor': ['xnor failed'] })
.success(function(error) {
expect(error).not.to.be.null
expect(error).to.be.instanceOf(Error)
expect(error.xnor).to.deep.equal(['xnor failed']);
Foo
.build({ field1: 33, field2: null })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!