#245: cover acccount switcher and prompt=select_account in CompleteState with tests

This commit is contained in:
SleepWalker 2017-01-29 13:59:28 +02:00
parent c1005b747b
commit c33f13e49a

View File

@ -7,6 +7,7 @@ import ActivationState from 'services/authFlow/ActivationState';
import AcceptRulesState from 'services/authFlow/AcceptRulesState';
import FinishState from 'services/authFlow/FinishState';
import PermissionsState from 'services/authFlow/PermissionsState';
import ChooseAccountState from 'services/authFlow/ChooseAccountState';
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
@ -153,6 +154,122 @@ describe('CompleteState', () => {
state.enter(context);
});
it('should transition to ChooseAccountState if user has multiple accs and switcher enabled', () => {
context.getState.returns({
user: {
isActive: true,
isGuest: false
},
accounts: {
available: [
{id: 1},
{id: 2}
],
active: {
id: 1
}
},
auth: {
isSwitcherEnabled: true,
oauth: {
clientId: 'ely.by',
prompt: []
}
}
});
expectState(mock, ChooseAccountState);
state.enter(context);
});
it('should NOT transition to ChooseAccountState if user has multiple accs and switcher disabled', () => {
context.getState.returns({
user: {
isActive: true,
isGuest: false
},
accounts: {
available: [
{id: 1},
{id: 2}
],
active: {
id: 1
}
},
auth: {
isSwitcherEnabled: false,
oauth: {
clientId: 'ely.by',
prompt: []
}
}
});
expectRun(mock, 'oAuthComplete', {})
.returns({then() {}});
state.enter(context);
});
it('should transition to ChooseAccountState if prompt=select_account and switcher enabled', () => {
context.getState.returns({
user: {
isActive: true,
isGuest: false
},
accounts: {
available: [
{id: 1}
],
active: {
id: 1
}
},
auth: {
isSwitcherEnabled: true,
oauth: {
clientId: 'ely.by',
prompt: ['select_account']
}
}
});
expectState(mock, ChooseAccountState);
state.enter(context);
});
it('should NOT transition to ChooseAccountState if prompt=select_account and switcher disabled', () => {
context.getState.returns({
user: {
isActive: true,
isGuest: false
},
accounts: {
available: [
{id: 1}
],
active: {
id: 1
}
},
auth: {
isSwitcherEnabled: false,
oauth: {
clientId: 'ely.by',
prompt: ['select_account']
}
}
});
expectRun(mock, 'oAuthComplete', {})
.returns({then() {}});
state.enter(context);
});
});
describe('when user completes oauth', () => {