2016-05-23 00:28:43 +05:30
|
|
|
import ResendActivationState from 'services/authFlow/ResendActivationState';
|
|
|
|
import CompleteState from 'services/authFlow/CompleteState';
|
|
|
|
import ActivationState from 'services/authFlow/ActivationState';
|
2016-05-23 09:20:10 +05:30
|
|
|
import RegisterState from 'services/authFlow/RegisterState';
|
2016-05-23 00:28:43 +05:30
|
|
|
|
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
|
|
|
|
|
|
|
|
describe('ResendActivationState', () => {
|
|
|
|
let state;
|
|
|
|
let context;
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = new ResendActivationState();
|
|
|
|
|
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /resend-activation', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
isActive: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expectNavigate(mock, '/resend-activation');
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
|
2016-05-23 09:20:10 +05:30
|
|
|
it('should navigate to /resend-activation for guests', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
isGuest: true,
|
2016-06-05 17:36:14 +05:30
|
|
|
isActive: false
|
2016-05-23 09:20:10 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expectNavigate(mock, '/resend-activation');
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
|
2016-05-23 00:28:43 +05:30
|
|
|
it('should transition to complete state if account activated', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
isActive: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expectState(mock, CompleteState);
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#resolve', () => {
|
|
|
|
it('should call resendActivation with payload', () => {
|
|
|
|
const payload = {email: 'foo@bar.com'};
|
|
|
|
|
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'resendActivation',
|
|
|
|
sinon.match.same(payload)
|
|
|
|
).returns({then() {}});
|
|
|
|
|
|
|
|
state.resolve(context, payload);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should transition to complete state on success', () => {
|
|
|
|
const promise = Promise.resolve();
|
|
|
|
|
|
|
|
mock.expects('run').returns(promise);
|
2016-06-05 17:36:14 +05:30
|
|
|
expectState(mock, ActivationState);
|
2016-05-23 00:28:43 +05:30
|
|
|
|
|
|
|
state.resolve(context);
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should NOT transition to complete state on fail', () => {
|
|
|
|
const promise = Promise.reject();
|
|
|
|
|
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
mock.expects('setState').never();
|
|
|
|
|
|
|
|
state.resolve(context);
|
|
|
|
|
|
|
|
return promise.catch(mock.verify.bind(mock));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-24 14:02:54 +05:30
|
|
|
describe('#reject', () => {
|
|
|
|
it('should transition to activate state on reject', () => {
|
|
|
|
expectState(mock, ActivationState);
|
|
|
|
|
|
|
|
state.reject(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-23 00:28:43 +05:30
|
|
|
describe('#goBack', () => {
|
2016-05-23 09:20:10 +05:30
|
|
|
it('should transition to activation', () => {
|
2016-05-23 00:28:43 +05:30
|
|
|
expectState(mock, ActivationState);
|
|
|
|
|
|
|
|
state.goBack(context);
|
|
|
|
});
|
2016-05-23 09:20:10 +05:30
|
|
|
|
2016-06-05 17:36:14 +05:30
|
|
|
it('should transition to register if it was active previousely', () => {
|
2016-05-23 09:20:10 +05:30
|
|
|
expectState(mock, RegisterState);
|
|
|
|
|
2016-06-05 17:36:14 +05:30
|
|
|
context.prevState = new RegisterState();
|
2016-05-23 09:20:10 +05:30
|
|
|
state.goBack(context);
|
|
|
|
});
|
2016-05-23 00:28:43 +05:30
|
|
|
});
|
|
|
|
});
|