2020-01-18 02:07:52 +05:30
|
|
|
import sinon, { SinonMock } from 'sinon';
|
2017-04-15 12:05:26 +05:30
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import ForgotPasswordState from 'app/services/authFlow/ForgotPasswordState';
|
|
|
|
import RecoverPasswordState from 'app/services/authFlow/RecoverPasswordState';
|
|
|
|
import LoginState from 'app/services/authFlow/LoginState';
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun, MockedAuthContext } from './helpers';
|
2016-05-15 02:23:58 +05:30
|
|
|
|
|
|
|
describe('ForgotPasswordState', () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
let state: ForgotPasswordState;
|
|
|
|
let context: MockedAuthContext;
|
|
|
|
let mock: SinonMock;
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = new ForgotPasswordState();
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /forgot-password if login set', () => {
|
|
|
|
expectNavigate(mock, '/forgot-password');
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.enter(context);
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#resolve', () => {
|
|
|
|
it('should call forgotPassword with email from payload', () => {
|
|
|
|
const expectedLogin = 'foo@bar.com';
|
2016-08-27 16:04:44 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'forgotPassword',
|
|
|
|
sinon.match({
|
|
|
|
login: expectedLogin,
|
|
|
|
}),
|
|
|
|
).returns(new Promise(() => {}));
|
2016-08-27 16:04:44 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.resolve(context, { login: expectedLogin });
|
|
|
|
});
|
2016-08-27 16:04:44 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
it('should transition to recoverPassword state on success', () => {
|
|
|
|
const promise = Promise.resolve();
|
|
|
|
const expectedLogin = 'foo@bar.com';
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
mock.expects('run').twice().returns(promise);
|
|
|
|
expectState(mock, RecoverPasswordState);
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.resolve(context, { login: expectedLogin });
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return promise;
|
|
|
|
});
|
2017-04-19 10:41:05 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
it('should run setLogin on success', () => {
|
|
|
|
const promise = Promise.resolve();
|
|
|
|
const expectedLogin = 'foo@bar.com';
|
2017-04-19 10:41:05 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
mock.expects('run').withArgs('forgotPassword').returns(promise);
|
|
|
|
expectState(mock, RecoverPasswordState);
|
|
|
|
mock.expects('run').withArgs('setLogin', expectedLogin);
|
2017-04-19 10:41:05 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.resolve(context, { login: expectedLogin });
|
2017-04-19 10:41:05 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return promise;
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should navigate to /send-message', () => {
|
|
|
|
expectState(mock, RecoverPasswordState);
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.reject(context);
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#goBack', () => {
|
|
|
|
it('should transition to login state', () => {
|
|
|
|
expectState(mock, LoginState);
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.goBack(context);
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
});
|
|
|
|
});
|