Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. export function changePassword(userId, oldPass, newPass) {
  2. var query = User.findById(userId);
  3. return query.exec()
  4. .then(user => {
  5. if (user.authenticate(oldPass)) {
  6. user.password = newPass;
  7. return user.save();
  8. } else {
  9. // I want to test that this Exception is thrown
  10. throw new UserNotAuthenticatedError();
  11. }
  12. });
  13. }
  14.  
  15. describe('#changePassword', function() {
  16. it('should throw a UserNotAuthenticatedError when passing wrong password', function() {
  17. var userId = user._id;
  18. var wrongPwd = 'wrongpassword';
  19. var newPwd = 'new password';
  20. // so far the following only tells me that the Promise was rejected, but
  21. // I WANT TO TEST THAT THE REJECTION WAS DUE TO A 'UserNotAuthenticatedError'
  22. UserService.changePassword(userId, wrongPwd, newPwd).should.be.rejected;
  23. });
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement