2016-08-03 00:29:29 +05:30
|
|
|
import AcceptRulesState from 'services/authFlow/AcceptRulesState';
|
|
|
|
import CompleteState from 'services/authFlow/CompleteState';
|
|
|
|
|
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
|
|
|
|
|
|
|
|
describe('AcceptRulesState', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
let state;
|
|
|
|
let context;
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = new AcceptRulesState();
|
|
|
|
|
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /accept-rules', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
shouldAcceptRules: true,
|
|
|
|
isGuest: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expectNavigate(mock, '/accept-rules');
|
|
|
|
|
|
|
|
state.enter(context);
|
2016-08-03 00:29:29 +05:30
|
|
|
});
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should transition to complete state if rules accepted', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
shouldAcceptRules: false,
|
|
|
|
isGuest: false,
|
|
|
|
},
|
|
|
|
});
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
expectState(mock, CompleteState);
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.enter(context);
|
2016-08-03 00:29:29 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#resolve', () => {
|
|
|
|
it('should call acceptRules', () => {
|
|
|
|
expectRun(mock, 'acceptRules').returns(new Promise(() => {}));
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context);
|
|
|
|
});
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should transition to complete state on success', () => {
|
|
|
|
const promise = Promise.resolve();
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
expectState(mock, CompleteState);
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context);
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return promise;
|
|
|
|
});
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should NOT transition to complete state on fail', () => {
|
|
|
|
const promise = Promise.reject();
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
mock.expects('setState').never();
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context);
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return promise.catch(mock.verify.bind(mock));
|
2016-08-03 00:29:29 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should logout', () => {
|
|
|
|
expectRun(mock, 'logout');
|
2016-08-03 00:29:29 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.reject(context);
|
2016-08-03 00:29:29 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-08-03 00:29:29 +05:30
|
|
|
});
|