2020-10-23 03:53:59 +05:30
|
|
|
import expect from 'app/test/unexpected';
|
|
|
|
import sinon, { SinonMock } from 'sinon';
|
|
|
|
|
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
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun, MockedAuthContext } from './helpers';
|
2016-11-19 20:11:15 +05:30
|
|
|
|
|
|
|
describe('ChooseAccountState', () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
let state: ChooseAccountState;
|
|
|
|
let context: MockedAuthContext;
|
|
|
|
let mock: SinonMock;
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = new ChooseAccountState();
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /oauth/choose-account', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
auth: {
|
|
|
|
oauth: {},
|
|
|
|
},
|
|
|
|
});
|
2018-02-18 01:29:35 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
expectNavigate(mock, '/oauth/choose-account');
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.enter(context);
|
|
|
|
});
|
2018-02-18 01:29:35 +05:30
|
|
|
|
2020-05-24 04:38:24 +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
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
expectNavigate(mock, '/choose-account');
|
2018-02-18 01:29:35 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.enter(context);
|
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#resolve', () => {
|
2020-10-23 03:53:59 +05:30
|
|
|
it('should transition to complete if an existing account was chosen', () => {
|
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'authenticate',
|
|
|
|
sinon.match({
|
|
|
|
id: 123,
|
|
|
|
}),
|
|
|
|
).returns(Promise.resolve());
|
|
|
|
expectRun(mock, 'setAccountSwitcher', false);
|
2020-05-24 04:38:24 +05:30
|
|
|
expectState(mock, CompleteState);
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
return expect(state.resolve(context, { id: 123 }), 'to be fulfilled');
|
2020-05-24 04:38:24 +05:30
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-05-24 04:38:24 +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
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
// Assert nothing returned
|
|
|
|
return expect(state.resolve(context, {}), 'to be undefined');
|
2020-05-24 04:38:24 +05:30
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should logout', () => {
|
|
|
|
expectRun(mock, 'logout');
|
2016-11-19 20:11:15 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.reject(context);
|
|
|
|
});
|
2016-11-19 20:11:15 +05:30
|
|
|
});
|
|
|
|
});
|