Catch errors on invalidate update

This commit is contained in:
loay 2017-08-16 17:14:17 -04:00
parent b3602bdd18
commit bf4b5de648
1 changed files with 33 additions and 0 deletions

View File

@ -417,6 +417,39 @@ describe('User', function() {
}); });
}); });
it('rejects updating with empty password using replaceAttributes', function(done) {
User.create({email: 'b@example.com', password: pass72Char}, function(err, userCreated) {
if (err) return done(err);
userCreated.replaceAttributes({'password': ''}, function(err, userUpdated) {
expect(err.code).to.equal('INVALID_PASSWORD');
expect(err.statusCode).to.equal(422);
done();
});
});
});
it('rejects updating with empty password using updateOrCreate', function(done) {
User.create({email: 'b@example.com', password: pass72Char}, function(err, userCreated) {
if (err) return done(err);
User.updateOrCreate({id: userCreated.id, 'password': ''}, function(err, userUpdated) {
expect(err.code).to.equal('INVALID_PASSWORD');
expect(err.statusCode).to.equal(422);
done();
});
});
});
it('rejects updating with empty password using updateAll', function(done) {
User.create({email: 'b@example.com', password: pass72Char}, function(err, userCreated) {
if (err) return done(err);
User.updateAll({where: {id: userCreated.id}}, {'password': ''}, function(err, userUpdated) {
expect(err.code).to.equal('INVALID_PASSWORD');
expect(err.statusCode).to.equal(422);
done();
});
});
});
it('rejects passwords longer than 72 characters', function(done) { it('rejects passwords longer than 72 characters', function(done) {
User.create({email: 'b@c.com', password: pass73Char}, function(err) { User.create({email: 'b@c.com', password: pass73Char}, function(err) {
expect(err.code).to.equal('PASSWORD_TOO_LONG'); expect(err.code).to.equal('PASSWORD_TOO_LONG');