2017-01-29 17:42:08 +05:30
|
|
|
import expect from 'unexpected';
|
2016-12-10 21:28:47 +05:30
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2016-03-21 11:46:37 +05:30
|
|
|
import PasswordState from 'services/authFlow/PasswordState';
|
|
|
|
import CompleteState from 'services/authFlow/CompleteState';
|
|
|
|
import LoginState from 'services/authFlow/LoginState';
|
|
|
|
import ForgotPasswordState from 'services/authFlow/ForgotPasswordState';
|
|
|
|
|
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun } from './helpers';
|
|
|
|
|
|
|
|
describe('PasswordState', () => {
|
|
|
|
let state;
|
|
|
|
let context;
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = new PasswordState();
|
|
|
|
|
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /password', () => {
|
|
|
|
context.getState.returns({
|
2016-11-13 02:01:44 +05:30
|
|
|
user: {isGuest: true},
|
|
|
|
auth: {login: 'foo'}
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectNavigate(mock, '/password');
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should transition to complete if not guest', () => {
|
|
|
|
context.getState.returns({
|
2016-11-13 02:01:44 +05:30
|
|
|
user: {isGuest: false},
|
|
|
|
auth: {login: null}
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expectState(mock, CompleteState);
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#resolve', () => {
|
2016-11-13 02:01:44 +05:30
|
|
|
it('should call login with login and password', () => {
|
|
|
|
const expectedLogin = 'foo';
|
|
|
|
const expectedPassword = 'bar';
|
2016-06-04 19:16:39 +05:30
|
|
|
const expectedRememberMe = true;
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2016-11-13 02:01:44 +05:30
|
|
|
context.getState.returns({
|
|
|
|
auth: {
|
|
|
|
login: expectedLogin
|
|
|
|
}
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
|
|
|
|
2016-11-13 02:01:44 +05:30
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'login',
|
|
|
|
sinon.match({
|
|
|
|
login: expectedLogin,
|
|
|
|
password: expectedPassword,
|
|
|
|
rememberMe: expectedRememberMe,
|
|
|
|
})
|
2016-12-10 21:28:47 +05:30
|
|
|
).returns(Promise.resolve());
|
2016-03-21 11:46:37 +05:30
|
|
|
expectState(mock, CompleteState);
|
|
|
|
|
2017-01-29 17:42:08 +05:30
|
|
|
const payload = {password: expectedPassword, rememberMe: expectedRememberMe};
|
2016-03-21 11:46:37 +05:30
|
|
|
|
2017-01-29 17:42:08 +05:30
|
|
|
return expect(state.resolve(context, payload), 'to be fulfilled');
|
2016-03-21 11:46:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#reject', () => {
|
|
|
|
it('should transition to forgot password state', () => {
|
|
|
|
expectState(mock, ForgotPasswordState);
|
|
|
|
|
|
|
|
state.reject(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#goBack', () => {
|
2016-11-13 02:01:44 +05:30
|
|
|
it('should transition to login state', () => {
|
|
|
|
expectRun(mock, 'setLogin', null);
|
2016-03-21 11:46:37 +05:30
|
|
|
expectState(mock, LoginState);
|
|
|
|
|
|
|
|
state.goBack(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|