2016-12-07 02:38:51 +05:30
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2016-03-21 11:46:37 +05:30
|
|
|
import RegisterState from 'services/authFlow/RegisterState';
|
|
|
|
import CompleteState from 'services/authFlow/CompleteState';
|
2016-07-24 14:02:54 +05:30
|
|
|
import ActivationState from 'services/authFlow/ActivationState';
|
2016-05-23 09:20:10 +05:30
|
|
|
import ResendActivationState from 'services/authFlow/ResendActivationState';
|
2016-03-21 11:46:37 +05:30
|
|
|
|
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
|
|
|
|
|
|
|
|
describe('RegisterState', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
let state;
|
|
|
|
let context;
|
|
|
|
let mock;
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = new RegisterState();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /register', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
user: { isGuest: true },
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
expectNavigate(mock, '/register');
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.enter(context);
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#resolve', () => {
|
|
|
|
it('should register on resolve', () => {
|
|
|
|
const payload = {};
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
expectRun(mock, 'register', sinon.match.same(payload)).returns(
|
|
|
|
new Promise(() => {}),
|
|
|
|
);
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context, payload);
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should transition to complete after register', () => {
|
|
|
|
const payload = {};
|
|
|
|
const promise = Promise.resolve();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
expectState(mock, CompleteState);
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context, payload);
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return promise;
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should NOT transition to complete if register fails', () => {
|
|
|
|
const promise = Promise.reject();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
mock.expects('setState').never();
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context);
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return promise.catch(mock.verify.bind(mock));
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-05-23 09:20:10 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should transition to activation', () => {
|
|
|
|
expectState(mock, ActivationState);
|
2016-07-24 14:02:54 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.reject(context, {});
|
|
|
|
});
|
2016-07-24 14:02:54 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should transition to resend-activation', () => {
|
|
|
|
expectState(mock, ResendActivationState);
|
2016-05-23 09:20:10 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.reject(context, { requestEmail: true });
|
2016-05-23 09:20:10 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|