2020-01-18 02:07:52 +05:30
|
|
|
import sinon, { SinonMock } from 'sinon';
|
2016-12-07 02:38:51 +05:30
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import RecoverPasswordState from 'app/services/authFlow/RecoverPasswordState';
|
|
|
|
import CompleteState from 'app/services/authFlow/CompleteState';
|
|
|
|
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('RecoverPasswordState', () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
let state: RecoverPasswordState;
|
|
|
|
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 RecoverPasswordState();
|
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 /recover-password', () => {
|
|
|
|
const expectedPath = '/recover-password';
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
context.getRequest.returns({ path: expectedPath });
|
2016-06-15 11:32:12 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
expectNavigate(mock, expectedPath);
|
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
|
|
|
it('should navigate to /recover-password/key', () => {
|
|
|
|
const expectedPath = '/recover-password/sasx5AS4d61';
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
context.getRequest.returns({ path: expectedPath });
|
2016-06-15 11:32:12 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
expectNavigate(mock, expectedPath);
|
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 recoverPassword with provided payload', () => {
|
|
|
|
const expectedPayload = {
|
2024-08-28 16:37:23 +05:30
|
|
|
key: '123',
|
2020-05-24 04:38:24 +05:30
|
|
|
newPassword: '123',
|
|
|
|
newRePassword: '123',
|
|
|
|
};
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
expectRun(mock, 'recoverPassword', sinon.match(expectedPayload)).returns(new Promise(() => {}));
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.resolve(context, expectedPayload);
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
it('should transition to complete state on success', () => {
|
|
|
|
const promise = Promise.resolve();
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
expectState(mock, CompleteState);
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2024-08-28 16:37:23 +05:30
|
|
|
state.resolve(context, { key: '', newPassword: '', newRePassword: '' });
|
2016-05-15 02:23:58 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return promise;
|
|
|
|
});
|
2016-05-23 00:28:43 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
it('should NOT transition to complete state on fail', () => {
|
|
|
|
const promise = Promise.reject();
|
2016-05-23 00:28:43 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
mock.expects('setState').never();
|
2016-05-23 00:28:43 +05:30
|
|
|
|
2024-08-28 16:37:23 +05:30
|
|
|
state.resolve(context, { key: '', newPassword: '', newRePassword: '' });
|
2016-05-23 00:28:43 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return promise.catch(mock.verify.bind(mock));
|
|
|
|
});
|
2016-05-15 02:23:58 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should run contactUs popup', () => {
|
|
|
|
expectRun(mock, 'contactUs');
|
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
|
|
|
});
|
|
|
|
});
|