From 05b82101bf8f04234c6b0fcda61b8af22ad72aa4 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Mon, 23 May 2016 06:50:10 +0300 Subject: [PATCH] Resend activation from register state --- src/services/authFlow/RegisterState.js | 2 ++ .../authFlow/ResendActivationState.js | 13 +++++-- tests/services/authFlow/RegisterState.test.js | 9 +++++ .../authFlow/ResendActivationState.test.js | 34 ++++++++++++++++++- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/services/authFlow/RegisterState.js b/src/services/authFlow/RegisterState.js index cdc03c9..b360368 100644 --- a/src/services/authFlow/RegisterState.js +++ b/src/services/authFlow/RegisterState.js @@ -1,5 +1,6 @@ import AbstractState from './AbstractState'; import CompleteState from './CompleteState'; +import ResendActivationState from './ResendActivationState'; export default class RegisterState extends AbstractState { enter(context) { @@ -18,5 +19,6 @@ export default class RegisterState extends AbstractState { } reject(context) { + context.setState(new ResendActivationState()); } } diff --git a/src/services/authFlow/ResendActivationState.js b/src/services/authFlow/ResendActivationState.js index 4383200..4d65447 100644 --- a/src/services/authFlow/ResendActivationState.js +++ b/src/services/authFlow/ResendActivationState.js @@ -1,15 +1,16 @@ import AbstractState from './AbstractState'; import CompleteState from './CompleteState'; import ActivationState from './ActivationState'; +import RegisterState from './RegisterState'; export default class ResendActivationState extends AbstractState { enter(context) { const {user} = context.getState(); - if (user.isActive) { + if (user.isActive && !user.isGuest) { context.setState(new CompleteState()); } else { - context.navigate('/repeat-message'); + context.navigate('/resend-activation'); } } @@ -19,6 +20,12 @@ export default class ResendActivationState extends AbstractState { } goBack(context) { - context.setState(new ActivationState()); + const {user} = context.getState(); + + if (user.isGuest) { + context.setState(new RegisterState()); + } else { + context.setState(new ActivationState()); + } } } diff --git a/tests/services/authFlow/RegisterState.test.js b/tests/services/authFlow/RegisterState.test.js index 2484f68..e6fd1fc 100644 --- a/tests/services/authFlow/RegisterState.test.js +++ b/tests/services/authFlow/RegisterState.test.js @@ -1,5 +1,6 @@ import RegisterState from 'services/authFlow/RegisterState'; import CompleteState from 'services/authFlow/CompleteState'; +import ResendActivationState from 'services/authFlow/ResendActivationState'; import { bootstrap, expectState, expectNavigate, expectRun } from './helpers'; @@ -78,4 +79,12 @@ describe('RegisterState', () => { return promise.catch(mock.verify.bind(mock)); }); }); + + describe('#reject', () => { + it('should transition to resend-activation', () => { + expectState(mock, ResendActivationState); + + state.reject(context); + }); + }); }); diff --git a/tests/services/authFlow/ResendActivationState.test.js b/tests/services/authFlow/ResendActivationState.test.js index 714a7af..9273de6 100644 --- a/tests/services/authFlow/ResendActivationState.test.js +++ b/tests/services/authFlow/ResendActivationState.test.js @@ -1,6 +1,7 @@ import ResendActivationState from 'services/authFlow/ResendActivationState'; import CompleteState from 'services/authFlow/CompleteState'; import ActivationState from 'services/authFlow/ActivationState'; +import RegisterState from 'services/authFlow/RegisterState'; import { bootstrap, expectState, expectNavigate, expectRun } from './helpers'; @@ -35,6 +36,19 @@ describe('ResendActivationState', () => { state.enter(context); }); + it('should navigate to /resend-activation for guests', () => { + context.getState.returns({ + user: { + isGuest: true, + isActive: true + } + }); + + expectNavigate(mock, '/resend-activation'); + + state.enter(context); + }); + it('should transition to complete state if account activated', () => { context.getState.returns({ user: { @@ -86,10 +100,28 @@ describe('ResendActivationState', () => { }); describe('#goBack', () => { - it('should transition to resend-activation', () => { + it('should transition to activation', () => { + context.getState.returns({ + user: { + isGuest: false + } + }); + expectState(mock, ActivationState); state.goBack(context); }); + + it('should transition to register if guest', () => { + context.getState.returns({ + user: { + isGuest: true + } + }); + + expectState(mock, RegisterState); + + state.goBack(context); + }); }); });