accounts-frontend/packages/app/services/authFlow/ChooseAccountState.test.ts

75 lines
2.0 KiB
TypeScript
Raw Normal View History

import ChooseAccountState from 'app/services/authFlow/ChooseAccountState';
import CompleteState from 'app/services/authFlow/CompleteState';
import LoginState from 'app/services/authFlow/LoginState';
import { SinonMock } from 'sinon';
2020-05-24 04:38:24 +05:30
import { bootstrap, expectState, expectNavigate, expectRun, MockedAuthContext } from './helpers';
describe('ChooseAccountState', () => {
2020-05-24 04:38:24 +05:30
let state: ChooseAccountState;
let context: MockedAuthContext;
let mock: SinonMock;
2020-05-24 04:38:24 +05:30
beforeEach(() => {
state = new ChooseAccountState();
2020-05-24 04:38:24 +05:30
const data = bootstrap();
context = data.context;
mock = data.mock;
});
2020-05-24 04:38:24 +05:30
afterEach(() => {
mock.verify();
});
2020-05-24 04:38:24 +05:30
describe('#enter', () => {
it('should navigate to /oauth/choose-account', () => {
context.getState.returns({
auth: {
oauth: {},
},
});
2020-05-24 04:38:24 +05:30
expectNavigate(mock, '/oauth/choose-account');
2020-05-24 04:38:24 +05:30
state.enter(context);
});
2020-05-24 04:38:24 +05:30
it('should navigate to /choose-account if not oauth', () => {
context.getState.returns({
auth: {
oauth: null,
},
});
2020-05-24 04:38:24 +05:30
expectNavigate(mock, '/choose-account');
2020-05-24 04:38:24 +05:30
state.enter(context);
});
});
2020-05-24 04:38:24 +05:30
describe('#resolve', () => {
it('should transition to complete if existed account was choosen', () => {
expectState(mock, CompleteState);
2020-05-24 04:38:24 +05:30
state.resolve(context, { id: 123 });
});
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);
2020-05-24 04:38:24 +05:30
state.resolve(context, {});
});
});
2020-05-24 04:38:24 +05:30
describe('#reject', () => {
it('should logout', () => {
expectRun(mock, 'logout');
2020-05-24 04:38:24 +05:30
state.reject(context);
});
});
});