Merge pull request #3570 from strongloop/catch-err

Catch errors on invalidate update
This commit is contained in:
Loay 2017-08-17 11:24:57 -04:00 committed by GitHub
commit 4a8e3f1327
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) {
User.create({email: 'b@c.com', password: pass73Char}, function(err) {
expect(err.code).to.equal('PASSWORD_TOO_LONG');