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 ActivationState from 'app/services/authFlow/ActivationState';
|
|
|
|
import CompleteState from 'app/services/authFlow/CompleteState';
|
|
|
|
import ResendActivationState from 'app/services/authFlow/ResendActivationState';
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun, MockedAuthContext } from './helpers';
|
2016-03-21 11:46:37 +05:30
|
|
|
|
|
|
|
describe('ActivationState', () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
let state: ActivationState;
|
|
|
|
let context: MockedAuthContext;
|
|
|
|
let mock: SinonMock;
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = new ActivationState();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /activation', () => {
|
|
|
|
const expectedPath = '/activation';
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
isActive: false,
|
|
|
|
},
|
|
|
|
});
|
2016-03-21 11:46:37 +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, '/activation');
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.enter(context);
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
it('should navigate to /activation/key', () => {
|
|
|
|
const expectedPath = '/activation/sasx5AS4d61';
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
isActive: false,
|
|
|
|
},
|
|
|
|
});
|
2016-06-05 17:46:41 +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-06-05 17:46:41 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.enter(context);
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#resolve', () => {
|
|
|
|
it('should call activate with payload', () => {
|
2024-08-28 16:37:23 +05:30
|
|
|
const payload = { key: 'mock' };
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2024-08-28 16:37:23 +05:30
|
|
|
expectRun(mock, 'activate', sinon.match.same('mock')).returns(new Promise(() => {}));
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.resolve(context, payload);
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
it('should transition to complete state on success', () => {
|
|
|
|
const promise = Promise.resolve();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
expectState(mock, CompleteState);
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2024-08-28 16:37:23 +05:30
|
|
|
state.resolve(context, { key: 'mock' });
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return promise;
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
it('should NOT transition to complete state on fail', () => {
|
|
|
|
const promise = Promise.reject();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
mock.expects('setState').never();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2024-08-28 16:37:23 +05:30
|
|
|
state.resolve(context, { key: 'mock' });
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return promise.catch(mock.verify.bind(mock));
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
2016-05-23 00:28:43 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should transition to resend-activation', () => {
|
|
|
|
expectState(mock, ResendActivationState);
|
2016-05-23 00:28:43 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.reject(context);
|
|
|
|
});
|
2016-05-23 00:28:43 +05:30
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|