diff --git a/src/services/authFlow/ForgotPasswordState.js b/src/services/authFlow/ForgotPasswordState.js index 5155ddc..187fa90 100644 --- a/src/services/authFlow/ForgotPasswordState.js +++ b/src/services/authFlow/ForgotPasswordState.js @@ -18,8 +18,8 @@ export default class ForgotPasswordState extends AbstractState { } } - resolve(context) { - context.run('forgotPassword', {login: this.getLogin(context)}) + resolve(context, payload = {}) { + context.run('forgotPassword', {login: payload.email || this.getLogin(context)}) .then(() => context.setState(new RecoverPasswordState())); } diff --git a/tests/services/authFlow/ForgotPasswordState.test.js b/tests/services/authFlow/ForgotPasswordState.test.js index bde9651..eb27d58 100644 --- a/tests/services/authFlow/ForgotPasswordState.test.js +++ b/tests/services/authFlow/ForgotPasswordState.test.js @@ -84,6 +84,25 @@ describe('ForgotPasswordState', () => { state.resolve(context, {}); }); + it('should call forgotPassword with email from payload if any', () => { + const expectedLogin = 'foo@bar.com'; + context.getState.returns({ + user: { + email: 'should.not@be.used' + } + }); + + expectRun( + mock, + 'forgotPassword', + sinon.match({ + login: expectedLogin + }) + ).returns({then() {}}); + + state.resolve(context, {email: expectedLogin}); + }); + it('should call forgotPassword with username', () => { const expectedLogin = 'foobar'; context.getState.returns({