#251: fix forgot password panel

This commit is contained in:
SleepWalker 2016-11-23 08:05:28 +02:00
parent 5ad7ee4b9d
commit 1e593019be
4 changed files with 20 additions and 65 deletions

View File

@ -5,14 +5,8 @@ import RecoverPasswordState from './RecoverPasswordState';
export default class ForgotPasswordState extends AbstractState {
enter(context) {
const {user} = context.getState();
if (user.isGuest) {
if (this.getLogin(context)) {
context.navigate('/forgot-password');
} else {
context.setState(new LoginState());
}
if (this.getLogin(context)) {
context.navigate('/forgot-password');
} else {
context.setState(new CompleteState());
}
@ -32,8 +26,8 @@ export default class ForgotPasswordState extends AbstractState {
}
getLogin(context) {
const {user} = context.getState();
const {auth} = context.getState();
return user.email || user.username;
return auth.login;
}
}

View File

@ -4,9 +4,9 @@ import CompleteState from './CompleteState';
export default class RecoverPasswordState extends AbstractState {
enter(context) {
const {user} = context.getState();
const {auth} = context.getState();
if (user.isGuest) {
if (auth.login) {
const url = context.getRequest().path.includes('/recover-password')
? context.getRequest().path
: '/recover-password';

View File

@ -23,9 +23,9 @@ describe('ForgotPasswordState', () => {
});
describe('#enter', () => {
it('should navigate to /forgot-password if email set', () => {
it('should navigate to /forgot-password if login set', () => {
context.getState.returns({
user: {isGuest: true, email: 'foo@bar.com'}
auth: {login: 'foo@bar.com'}
});
expectNavigate(mock, '/forgot-password');
@ -33,43 +33,23 @@ describe('ForgotPasswordState', () => {
state.enter(context);
});
it('should navigate to /forgot-password if username set', () => {
it('should transition to complete if no login', () => {
context.getState.returns({
user: {isGuest: true, username: 'foobar'}
});
expectNavigate(mock, '/forgot-password');
state.enter(context);
});
it('should transition to complete if not guest', () => {
context.getState.returns({
user: {isGuest: false}
auth: {}
});
expectState(mock, CompleteState);
state.enter(context);
});
it('should transition to login if no identity', () => {
context.getState.returns({
user: {isGuest: true}
});
expectState(mock, LoginState);
state.enter(context);
});
});
describe('#resolve', () => {
it('should call forgotPassword with email', () => {
it('should call forgotPassword with login', () => {
const expectedLogin = 'foo@bar.com';
context.getState.returns({
user: {
email: expectedLogin
auth: {
login: expectedLogin
}
});
@ -87,8 +67,8 @@ describe('ForgotPasswordState', () => {
it('should call forgotPassword with email from payload if any', () => {
const expectedLogin = 'foo@bar.com';
context.getState.returns({
user: {
email: 'should.not@be.used'
auth: {
login: 'should.not@be.used'
}
});
@ -103,31 +83,12 @@ describe('ForgotPasswordState', () => {
state.resolve(context, {email: expectedLogin});
});
it('should call forgotPassword with username', () => {
const expectedLogin = 'foobar';
context.getState.returns({
user: {
username: expectedLogin
}
});
expectRun(
mock,
'forgotPassword',
sinon.match({
login: expectedLogin
})
).returns({then() {}});
state.resolve(context, {});
});
it('should transition to recoverPassword state on success', () => {
const promise = Promise.resolve();
const expectedLogin = 'foo@bar.com';
context.getState.returns({
user: {
email: expectedLogin
auth: {
login: expectedLogin
}
});

View File

@ -25,7 +25,7 @@ describe('RecoverPasswordState', () => {
it('should navigate to /recover-password', () => {
const expectedPath = '/recover-password';
context.getState.returns({
user: {isGuest: true}
auth: {login: 'foo'}
});
context.getRequest.returns({path: expectedPath});
@ -38,7 +38,7 @@ describe('RecoverPasswordState', () => {
it('should navigate to /recover-password/key', () => {
const expectedPath = '/recover-password/sasx5AS4d61';
context.getState.returns({
user: {isGuest: true}
auth: {login: 'foo'}
});
context.getRequest.returns({path: expectedPath});
@ -50,7 +50,7 @@ describe('RecoverPasswordState', () => {
it('should transition to complete if not guest', () => {
context.getState.returns({
user: {isGuest: false}
auth: {}
});
expectState(mock, CompleteState);