2016-05-15 02:23:58 +05:30
|
|
|
import ForgotPasswordState from 'services/authFlow/ForgotPasswordState';
|
|
|
|
import RecoverPasswordState from 'services/authFlow/RecoverPasswordState';
|
|
|
|
import CompleteState from 'services/authFlow/CompleteState';
|
|
|
|
import LoginState from 'services/authFlow/LoginState';
|
|
|
|
|
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
|
|
|
|
|
|
|
|
describe('ForgotPasswordState', () => {
|
|
|
|
let state;
|
|
|
|
let context;
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = new ForgotPasswordState();
|
|
|
|
|
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#enter', () => {
|
2016-11-23 11:35:28 +05:30
|
|
|
it('should navigate to /forgot-password if login set', () => {
|
2016-05-15 02:23:58 +05:30
|
|
|
context.getState.returns({
|
2016-11-23 11:35:28 +05:30
|
|
|
auth: {login: 'foo@bar.com'}
|
2016-05-15 02:23:58 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectNavigate(mock, '/forgot-password');
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
|
2016-11-23 11:35:28 +05:30
|
|
|
it('should transition to complete if no login', () => {
|
2016-05-15 02:23:58 +05:30
|
|
|
context.getState.returns({
|
2016-11-23 11:35:28 +05:30
|
|
|
auth: {}
|
2016-05-15 02:23:58 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectState(mock, CompleteState);
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#resolve', () => {
|
2016-11-23 11:35:28 +05:30
|
|
|
it('should call forgotPassword with login', () => {
|
2016-05-15 02:23:58 +05:30
|
|
|
const expectedLogin = 'foo@bar.com';
|
|
|
|
context.getState.returns({
|
2016-11-23 11:35:28 +05:30
|
|
|
auth: {
|
|
|
|
login: expectedLogin
|
2016-05-15 02:23:58 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'forgotPassword',
|
|
|
|
sinon.match({
|
|
|
|
login: expectedLogin
|
|
|
|
})
|
|
|
|
).returns({then() {}});
|
|
|
|
|
|
|
|
state.resolve(context, {});
|
|
|
|
});
|
|
|
|
|
2016-08-27 16:04:44 +05:30
|
|
|
it('should call forgotPassword with email from payload if any', () => {
|
|
|
|
const expectedLogin = 'foo@bar.com';
|
|
|
|
context.getState.returns({
|
2016-11-23 11:35:28 +05:30
|
|
|
auth: {
|
|
|
|
login: 'should.not@be.used'
|
2016-08-27 16:04:44 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'forgotPassword',
|
|
|
|
sinon.match({
|
|
|
|
login: expectedLogin
|
|
|
|
})
|
|
|
|
).returns({then() {}});
|
|
|
|
|
|
|
|
state.resolve(context, {email: expectedLogin});
|
|
|
|
});
|
|
|
|
|
2016-05-15 02:23:58 +05:30
|
|
|
it('should transition to recoverPassword state on success', () => {
|
|
|
|
const promise = Promise.resolve();
|
|
|
|
const expectedLogin = 'foo@bar.com';
|
|
|
|
context.getState.returns({
|
2016-11-23 11:35:28 +05:30
|
|
|
auth: {
|
|
|
|
login: expectedLogin
|
2016-05-15 02:23:58 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mock.expects('run').returns(promise);
|
|
|
|
expectState(mock, RecoverPasswordState);
|
|
|
|
|
|
|
|
state.resolve(context, {});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#reject', () => {
|
|
|
|
it('should navigate to /send-message', () => {
|
|
|
|
expectState(mock, RecoverPasswordState);
|
|
|
|
|
|
|
|
state.reject(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#goBack', () => {
|
|
|
|
it('should transition to login state', () => {
|
|
|
|
expectState(mock, LoginState);
|
|
|
|
|
|
|
|
state.goBack(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|