mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-03-02 14:13:03 +05:30
#251: fix forgot password panel
This commit is contained in:
parent
5ad7ee4b9d
commit
1e593019be
@ -5,14 +5,8 @@ import RecoverPasswordState from './RecoverPasswordState';
|
|||||||
|
|
||||||
export default class ForgotPasswordState extends AbstractState {
|
export default class ForgotPasswordState extends AbstractState {
|
||||||
enter(context) {
|
enter(context) {
|
||||||
const {user} = context.getState();
|
if (this.getLogin(context)) {
|
||||||
|
context.navigate('/forgot-password');
|
||||||
if (user.isGuest) {
|
|
||||||
if (this.getLogin(context)) {
|
|
||||||
context.navigate('/forgot-password');
|
|
||||||
} else {
|
|
||||||
context.setState(new LoginState());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
context.setState(new CompleteState());
|
context.setState(new CompleteState());
|
||||||
}
|
}
|
||||||
@ -32,8 +26,8 @@ export default class ForgotPasswordState extends AbstractState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getLogin(context) {
|
getLogin(context) {
|
||||||
const {user} = context.getState();
|
const {auth} = context.getState();
|
||||||
|
|
||||||
return user.email || user.username;
|
return auth.login;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import CompleteState from './CompleteState';
|
|||||||
|
|
||||||
export default class RecoverPasswordState extends AbstractState {
|
export default class RecoverPasswordState extends AbstractState {
|
||||||
enter(context) {
|
enter(context) {
|
||||||
const {user} = context.getState();
|
const {auth} = context.getState();
|
||||||
|
|
||||||
if (user.isGuest) {
|
if (auth.login) {
|
||||||
const url = context.getRequest().path.includes('/recover-password')
|
const url = context.getRequest().path.includes('/recover-password')
|
||||||
? context.getRequest().path
|
? context.getRequest().path
|
||||||
: '/recover-password';
|
: '/recover-password';
|
||||||
|
@ -23,9 +23,9 @@ describe('ForgotPasswordState', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#enter', () => {
|
describe('#enter', () => {
|
||||||
it('should navigate to /forgot-password if email set', () => {
|
it('should navigate to /forgot-password if login set', () => {
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {isGuest: true, email: 'foo@bar.com'}
|
auth: {login: 'foo@bar.com'}
|
||||||
});
|
});
|
||||||
|
|
||||||
expectNavigate(mock, '/forgot-password');
|
expectNavigate(mock, '/forgot-password');
|
||||||
@ -33,43 +33,23 @@ describe('ForgotPasswordState', () => {
|
|||||||
state.enter(context);
|
state.enter(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate to /forgot-password if username set', () => {
|
it('should transition to complete if no login', () => {
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {isGuest: true, username: 'foobar'}
|
auth: {}
|
||||||
});
|
|
||||||
|
|
||||||
expectNavigate(mock, '/forgot-password');
|
|
||||||
|
|
||||||
state.enter(context);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should transition to complete if not guest', () => {
|
|
||||||
context.getState.returns({
|
|
||||||
user: {isGuest: false}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expectState(mock, CompleteState);
|
expectState(mock, CompleteState);
|
||||||
|
|
||||||
state.enter(context);
|
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', () => {
|
describe('#resolve', () => {
|
||||||
it('should call forgotPassword with email', () => {
|
it('should call forgotPassword with login', () => {
|
||||||
const expectedLogin = 'foo@bar.com';
|
const expectedLogin = 'foo@bar.com';
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {
|
auth: {
|
||||||
email: expectedLogin
|
login: expectedLogin
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -87,8 +67,8 @@ describe('ForgotPasswordState', () => {
|
|||||||
it('should call forgotPassword with email from payload if any', () => {
|
it('should call forgotPassword with email from payload if any', () => {
|
||||||
const expectedLogin = 'foo@bar.com';
|
const expectedLogin = 'foo@bar.com';
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {
|
auth: {
|
||||||
email: 'should.not@be.used'
|
login: 'should.not@be.used'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -103,31 +83,12 @@ describe('ForgotPasswordState', () => {
|
|||||||
state.resolve(context, {email: expectedLogin});
|
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', () => {
|
it('should transition to recoverPassword state on success', () => {
|
||||||
const promise = Promise.resolve();
|
const promise = Promise.resolve();
|
||||||
const expectedLogin = 'foo@bar.com';
|
const expectedLogin = 'foo@bar.com';
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {
|
auth: {
|
||||||
email: expectedLogin
|
login: expectedLogin
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ describe('RecoverPasswordState', () => {
|
|||||||
it('should navigate to /recover-password', () => {
|
it('should navigate to /recover-password', () => {
|
||||||
const expectedPath = '/recover-password';
|
const expectedPath = '/recover-password';
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {isGuest: true}
|
auth: {login: 'foo'}
|
||||||
});
|
});
|
||||||
|
|
||||||
context.getRequest.returns({path: expectedPath});
|
context.getRequest.returns({path: expectedPath});
|
||||||
@ -38,7 +38,7 @@ describe('RecoverPasswordState', () => {
|
|||||||
it('should navigate to /recover-password/key', () => {
|
it('should navigate to /recover-password/key', () => {
|
||||||
const expectedPath = '/recover-password/sasx5AS4d61';
|
const expectedPath = '/recover-password/sasx5AS4d61';
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {isGuest: true}
|
auth: {login: 'foo'}
|
||||||
});
|
});
|
||||||
|
|
||||||
context.getRequest.returns({path: expectedPath});
|
context.getRequest.returns({path: expectedPath});
|
||||||
@ -50,7 +50,7 @@ describe('RecoverPasswordState', () => {
|
|||||||
|
|
||||||
it('should transition to complete if not guest', () => {
|
it('should transition to complete if not guest', () => {
|
||||||
context.getState.returns({
|
context.getState.returns({
|
||||||
user: {isGuest: false}
|
auth: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
expectState(mock, CompleteState);
|
expectState(mock, CompleteState);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user