From c33f13e49ab84683508195b23078c2742079a809 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sun, 29 Jan 2017 13:59:28 +0200 Subject: [PATCH] #245: cover acccount switcher and prompt=select_account in CompleteState with tests --- tests/services/authFlow/CompleteState.test.js | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/tests/services/authFlow/CompleteState.test.js b/tests/services/authFlow/CompleteState.test.js index fdef0be..0d1bf4a 100644 --- a/tests/services/authFlow/CompleteState.test.js +++ b/tests/services/authFlow/CompleteState.test.js @@ -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', () => {