From 11ef948854b0e9d24e39d1818b0170f7c9b97bed Mon Sep 17 00:00:00 2001 From: Amir Jafarian Date: Wed, 6 Apr 2016 13:14:56 -0400 Subject: [PATCH] Test coverages for hashed password * Test coverages for hashed password for replaceAttributes * Test coverages for hashed password for updateAttribute --- test/manipulation.test.js | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/manipulation.test.js b/test/manipulation.test.js index 70d353ab..4277ad25 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -37,6 +37,15 @@ describe('manipulation', function() { before(function setupStubUserModel(done) { StubUser = db.createModel('StubUser', { password: String }, { forceId: true }); StubUser.setter.password = function(plain) { + var hashed = false; + if (!plain) return; + var pos = plain.indexOf('-'); + if (pos !== -1) { + var head = plain.substr(0, pos); + var tail = plain.substr(pos + 1, plain.length); + hashed = head.toUpperCase() === tail; + } + if (hashed) return; this.$password = plain + '-' + plain.toUpperCase(); }; db.automigrate('StubUser', done); @@ -464,6 +473,22 @@ describe('manipulation', function() { done(); }); + it('should have updated password hashed with updateAttribute', + function(done) { + StubUser.create({ password: 'foo' }, function(err, created) { + if (err) return done(err); + created.updateAttribute('password', 'test', function(err, created) { + if (err) return done(err); + created.password.should.equal('test-TEST'); + StubUser.findById(created.id, function(err, found) { + if (err) return done(err); + found.password.should.equal('test-TEST'); + done(); + }); + }); + }); + }); + it('should update one attribute', function(done) { person.updateAttribute('name', 'Paul Graham', function(err, p) { if (err) return done(err); @@ -943,6 +968,23 @@ describe('manipulation', function() { }); }); + it('should have updated password hashed with replaceAttributes', + function(done) { + StubUser.create({ password: 'foo' }, function(err, created) { + if (err) return done(err); + created.replaceAttributes({ password: 'test' }, + function(err, created) { + if (err) return done(err); + created.password.should.equal('test-TEST'); + StubUser.findById(created.id, function(err, found) { + if (err) return done(err); + found.password.should.equal('test-TEST'); + done(); + }); + }); + }); + }); + it('works without options(promise variant)', function(done) { Post.findById(postInstance.id) .then(function(p) {