added some tests, fixed user reset tests

v1.18.x
Julian Lam 10 years ago
parent 66422acea2
commit 04f536854c

@ -195,7 +195,8 @@ describe('User', function() {
});
describe('passwordReset', function() {
var uid;
var uid,
code;
before(function(done) {
User.create({username: 'resetuser', password: '123456', email: 'reset@me.com'}, function(err, newUid) {
assert.ifError(err);
@ -204,21 +205,49 @@ describe('User', function() {
});
});
it('should create a new reset code and reset password', function(done) {
it('.generate() should generate a new reset code', function(done) {
User.reset.generate(uid, function(err, _code) {
assert.ifError(err);
assert(_code);
code = _code;
done();
});
});
it('.validate() should ensure that this new code is valid', function(done) {
User.reset.validate(code, function(err, valid) {
assert.ifError(err);
assert.strictEqual(valid, true);
done();
});
});
it('.validate() should correctly identify an invalid code', function(done) {
User.reset.validate(code + 'abcdef', function(err, valid) {
assert.ifError(err);
assert.strictEqual(valid, false);
done();
});
});
it('.send() should create a new reset code and reset password', function(done) {
User.reset.send('reset@me.com', function(err, code) {
assert.ifError(err);
assert(code);
done();
});
});
User.reset.commit(code, 'newpassword', function(err) {
assert.ifError(err);
it('.commit() should update the user\'s password', function(done) {
User.reset.commit(code, 'newpassword', function(err) {
assert.ifError(err);
db.getObjectField('user:' + uid, 'password', function(err, newPassword) {
db.getObjectField('user:' + uid, 'password', function(err, newPassword) {
assert.ifError(err);
Password.compare('newpassword', newPassword, function(err, match) {
assert.ifError(err);
Password.compare('newpassword', newPassword, function(err, match) {
assert.ifError(err);
assert(match);
done();
});
assert(match);
done();
});
});
});

Loading…
Cancel
Save