From fa8bca8d6e53284d8f208a8d8ecd168eb9ad2aa6 Mon Sep 17 00:00:00 2001 From: Sergey Reus Date: Wed, 30 Nov 2016 13:44:30 +0200 Subject: [PATCH] Emit resetPasswordRequest event with options --- common/models/user.js | 1 + test/user.test.js | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/common/models/user.js b/common/models/user.js index 368dace9..21a59c89 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -617,6 +617,7 @@ module.exports = function(User) { email: options.email, accessToken: accessToken, user: user, + options: options, }); }); }); diff --git a/test/user.test.js b/test/user.test.js index 16830bc4..69bd3a61 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -1815,7 +1815,10 @@ describe('User', function() { describe('Password Reset', function() { describe('User.resetPassword(options, cb)', function() { - var email = 'foo@bar.com'; + var options = { + email: 'foo@bar.com', + redirect: 'http://foobar.com/reset-password', + }; it('Requires email address to reset password', function(done) { User.resetPassword({ }, function(err) { @@ -1849,11 +1852,27 @@ describe('User', function() { }); }); + it('Checks that options exist', function(done) { + var calledBack = false; + + User.resetPassword(options, function() { + calledBack = true; + }); + + User.once('resetPasswordRequest', function(info) { + assert(info.options); + assert.equal(info.options, options); + assert(calledBack); + + done(); + }); + }); + it('Creates a temp accessToken to allow a user to change password', function(done) { var calledBack = false; User.resetPassword({ - email: email, + email: options.email, }, function() { calledBack = true; }); @@ -1867,7 +1886,7 @@ describe('User', function() { info.accessToken.user(function(err, user) { if (err) return done(err); - assert.equal(user.email, email); + assert.equal(user.email, options.email); done(); }); @@ -1896,7 +1915,7 @@ describe('User', function() { .post('/test-users/reset') .expect('Content-Type', /json/) .expect(204) - .send({email: email}) + .send({email: options.email}) .end(function(err, res) { if (err) return done(err);