2019-12-08 00:32:00 +05:30
|
|
|
import ChooseAccountState from 'app/services/authFlow/ChooseAccountState';
|
|
|
|
import CompleteState from 'app/services/authFlow/CompleteState';
|
|
|
|
import LoginState from 'app/services/authFlow/LoginState';
|
2016-11-19 20:11:15 +05:30
|
|
|
|
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
|
|
|
|
|
|
|
|
describe('ChooseAccountState', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
let state;
|
|
|
|
let context;
|
|
|
|
let mock;
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = new ChooseAccountState();
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /oauth/choose-account', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
auth: {
|
|
|
|
oauth: {},
|
|
|
|
},
|
|
|
|
});
|
2018-02-18 01:29:35 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
expectNavigate(mock, '/oauth/choose-account');
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.enter(context);
|
|
|
|
});
|
2018-02-18 01:29:35 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should navigate to /choose-account if not oauth', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
auth: {
|
|
|
|
oauth: null,
|
|
|
|
},
|
|
|
|
});
|
2018-02-18 01:29:35 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
expectNavigate(mock, '/choose-account');
|
2018-02-18 01:29:35 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.enter(context);
|
2016-11-19 20:11:15 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#resolve', () => {
|
|
|
|
it('should transition to complete if existed account was choosen', () => {
|
|
|
|
expectState(mock, CompleteState);
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context, { id: 123 });
|
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
it('should transition to login if user wants to add new account', () => {
|
|
|
|
expectNavigate(mock, '/login');
|
|
|
|
expectRun(mock, 'setLogin', null);
|
|
|
|
expectState(mock, LoginState);
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.resolve(context, {});
|
2016-11-19 20:11:15 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should logout', () => {
|
|
|
|
expectRun(mock, 'logout');
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
state.reject(context);
|
2016-11-19 20:11:15 +05:30
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
});
|