2016-03-21 11:46:37 +05:30
|
|
|
import ActivationState from 'services/authFlow/ActivationState';
|
|
|
|
import CompleteState from 'services/authFlow/CompleteState';
|
2016-05-23 00:28:43 +05:30
|
|
|
import ResendActivationState from 'services/authFlow/ResendActivationState';
|
2016-03-21 11:46:37 +05:30
|
|
|
|
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
|
|
|
|
|
|
|
|
describe('ActivationState', () => {
|
|
|
|
let state;
|
|
|
|
let context;
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = new ActivationState();
|
|
|
|
|
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /activation', () => {
|
2016-06-05 17:46:41 +05:30
|
|
|
const expectedPath = '/activation';
|
2016-03-21 11:46:37 +05:30
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
isActive: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-07 19:24:59 +05:30
|
|
|
context.getRequest.returns({path: expectedPath});
|
2016-06-15 11:32:12 +05:30
|
|
|
|
2016-03-21 11:46:37 +05:30
|
|
|
expectNavigate(mock, '/activation');
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
|
2016-06-05 17:46:41 +05:30
|
|
|
it('should navigate to /activation/key', () => {
|
|
|
|
const expectedPath = '/activation/sasx5AS4d61';
|
|
|
|
context.getState.returns({
|
|
|
|
user: {
|
|
|
|
isActive: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-07 19:24:59 +05:30
|
|
|
context.getRequest.returns({path: expectedPath});
|
2016-06-15 11:32:12 +05:30
|
|
|
|
2016-06-05 17:46:41 +05:30
|
|
|
expectNavigate(mock, expectedPath);
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
|
2016-03-21 11:46:37 +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 activate with payload', () => {
|
|
|
|
const payload = {};
|
|
|
|
|
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'activate',
|
|
|
|
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);
|
|
|
|
expectState(mock, CompleteState);
|
|
|
|
|
|
|
|
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-05-23 00:28:43 +05:30
|
|
|
|
|
|
|
describe('#reject', () => {
|
|
|
|
it('should transition to resend-activation', () => {
|
|
|
|
expectState(mock, ResendActivationState);
|
|
|
|
|
|
|
|
state.reject(context);
|
|
|
|
});
|
|
|
|
});
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|