#192: respect user-entered email in forgotPassword state

This commit is contained in:
SleepWalker 2016-08-27 13:34:44 +03:00
parent fdd56bc886
commit d1a1b2085b
2 changed files with 21 additions and 2 deletions

View File

@ -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()));
}

View File

@ -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({