Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function changePassword(userId, oldPass, newPass) {
- var query = User.findById(userId);
- return query.exec()
- .then(user => {
- if (user.authenticate(oldPass)) {
- user.password = newPass;
- return user.save();
- } else {
- // I want to test that this Exception is thrown
- throw new UserNotAuthenticatedError();
- }
- });
- }
- describe('#changePassword', function() {
- it('should throw a UserNotAuthenticatedError when passing wrong password', function() {
- var userId = user._id;
- var wrongPwd = 'wrongpassword';
- var newPwd = 'new password';
- // so far the following only tells me that the Promise was rejected, but
- // I WANT TO TEST THAT THE REJECTION WAS DUE TO A 'UserNotAuthenticatedError'
- UserService.changePassword(userId, wrongPwd, newPwd).should.be.rejected;
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement