Skip to content

Commit

Permalink
fix: don't remove User.isValid
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Nov 24, 2016
1 parent d1a346d commit 4eba117
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/cli/users/index.js
Expand Up @@ -117,15 +117,15 @@ export function findByResetPasswordToken(resetPasswordToken, done) {
return done(null, null)
}

// export function isValid(user, password) {
// var bdd = User.getBdd()
// if(user.actif === 1) {
// if(bcrypt.compareSync(password, user.password)) {
// return true
// }
// }
// return false;
// };
export function isValid(user, password) {
var bdd = User.getBdd()
if(user.actif === 1) {
if(bcrypt.compareSync(password, user.password)) {
return true
}
}
return false;
};

export function deactivate(id) {
var bdd = User.getBdd()
Expand Down
19 changes: 19 additions & 0 deletions test/users.js
Expand Up @@ -246,6 +246,25 @@ describe('users', function() {
User.getBdd.restore()
})

it('User.isValid', function(){
// stub
var sinonInstance = sinon.sandbox.create();
var stub = sinonInstance.stub(User, 'getBdd');
stub.returns(JSON.parse(JSON.stringify(this.fixture.users)))
var stubHashSync = sinonInstance.stub(bcrypt, 'compareSync');
stubHashSync.returns(true);

// test
var res = User.isValid(JSON.parse(JSON.stringify(this.fixture.users))[0])
chai.expect(res).to.be.equal(true)

// unstub
sinon.assert.calledOnce(User.getBdd)
User.getBdd.restore()
sinon.assert.calledOnce(bcrypt.compareSync)
bcrypt.compareSync.restore()
})

it('User.findSync', function(){
var sinonInstance = sinon.sandbox.create();
var stub = sinonInstance.stub(User, 'getBdd');
Expand Down

0 comments on commit 4eba117

Please sign in to comment.