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); + }); }); });