-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
2,836 additions
and
1,921 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/feature/Reset Password/forgot password/ForgotPasswordComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable no-shadow */ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import forgotPasswordAction from './forgotPasswordAction'; | ||
import '../resetPassword.scss'; | ||
|
||
export class ForgotPassword extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
email: '', | ||
}; | ||
} | ||
|
||
onChange = (e) => { | ||
this.setState({ [e.target.name]: e.target.value }); | ||
} | ||
|
||
onSubmit = (e) => { | ||
e.preventDefault(); | ||
const { email } = this.state; | ||
const { forgotPasswordAction } = this.props; | ||
forgotPasswordAction(email); | ||
} | ||
|
||
render() { | ||
const { email } = this.state; | ||
return ( | ||
<div className="form"> | ||
<br /> | ||
<div className="reset"> | ||
<h1> | ||
Reset Password | ||
</h1> | ||
<p> | ||
Please provide your email address. You will receive a link to reset your password. | ||
</p> | ||
</div> | ||
<form onSubmit={this.onSubmit}> | ||
<div className="inputForm"> | ||
<input id="email" type="email" name="email" placeholder="Email" onChange={this.onChange} value={email} /> | ||
</div> | ||
<div className="formButton"> | ||
<button type="submit" className="send">Send</button> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
email: state.email, | ||
}); | ||
export default connect(mapStateToProps, { forgotPasswordAction })(ForgotPassword); |
54 changes: 54 additions & 0 deletions
54
src/feature/Reset Password/forgot password/__tests__/forgotPasswordAction.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import configureStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import moxios from 'moxios'; | ||
import forgotPasswordAction from '../forgotPasswordAction'; | ||
|
||
const email = 'raymond@gmail.com'; | ||
const middleware = [thunk]; | ||
|
||
const mockStore = configureStore(middleware); | ||
|
||
const store = mockStore({}); | ||
|
||
describe('Forgot password', () => { | ||
beforeEach(() => { | ||
moxios.install(); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(); | ||
store.clearActions(); | ||
}); | ||
|
||
it('should send a reset password link', async () => { | ||
moxios.wait(() => { | ||
const resetPasswordLink = moxios.requests.mostRecent(); | ||
resetPasswordLink.respondWith({ | ||
status: 200, | ||
response: { | ||
data: { | ||
message: 'Email sent, please check your email' | ||
} | ||
} | ||
}); | ||
}); | ||
return store.dispatch(forgotPasswordAction(email)).then(() => { | ||
expect(store.getActions().length).toEqual(1); | ||
}); | ||
}); | ||
it('should throw an error when an email sent is an invalid', () => { | ||
moxios.wait(() => { | ||
const resetPasswordLink = moxios.requests.mostRecent(); | ||
resetPasswordLink.respondWith({ | ||
status: 404, | ||
response: { | ||
data: { | ||
error: `User with email: ${email} not found..` | ||
} | ||
} | ||
}); | ||
}); | ||
return store.dispatch(forgotPasswordAction('fddsfa@fdvdf.com')).then(() => { | ||
expect(store.getActions().length).toEqual(1); | ||
}); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
src/feature/Reset Password/forgot password/__tests__/forgotPasswordComponent.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { ForgotPassword } from '../ForgotPasswordComponent'; | ||
|
||
const forgotPassword = args => { | ||
const initialProps = { | ||
email: '', | ||
forgotPasswordAction: () => {}, | ||
handleSubmit: () => {} | ||
}; | ||
const props = { ...initialProps, ...args }; | ||
return shallow(<ForgotPassword {...props} />); | ||
}; | ||
|
||
let wrapper; | ||
|
||
beforeAll(() => { | ||
wrapper = forgotPassword(); | ||
wrapper.instance().onChange = jest.fn(); | ||
wrapper.instance().onChange(); | ||
}); | ||
|
||
describe('Input tests', () => { | ||
it('Should type in the Email field', () => { | ||
const Email = wrapper.find('input[name="email"]'); | ||
Email.simulate('change', { | ||
target: { value: 'raymond@gmail.com', name: 'email' }, | ||
}); | ||
expect(wrapper.state('email')).toEqual('raymond@gmail.com'); | ||
}); | ||
}); | ||
|
||
describe('Send button test', () => { | ||
let instance; | ||
let submitButton; | ||
beforeAll(() => { | ||
instance = wrapper.instance(); | ||
submitButton = wrapper.find('.send'); | ||
submitButton.simulate('click'); | ||
}); | ||
it('Should make a request to the server', () => { | ||
instance.forceUpdate(); | ||
wrapper.update(); | ||
const event = { | ||
preventDefault: jest.fn(), | ||
}; | ||
instance.onSubmit(event); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/feature/Reset Password/forgot password/__tests__/forgotPasswordReducers.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-disable import/named */ | ||
import forgotPasswordReducers, { initialState } from '../forgotPasswordReducers'; | ||
import { FORGOT_PASSWORD_SUCCESS, FORGOT_PASSWORD_FAIL } from '../forgotPasswordActionTypes'; | ||
|
||
describe('forgot password reducer', () => { | ||
test('EMAIL_SENT_SUCCESSFULLY', () => { | ||
const reducer = forgotPasswordReducers(initialState, { | ||
type: FORGOT_PASSWORD_SUCCESS, | ||
message: { payload: { sendEmail: 'raymond@gmail.com' } } | ||
}); | ||
expect(reducer).toHaveProperty('message'); | ||
}); | ||
test('EMAIL_FAILED_TO_BE_SENT', () => { | ||
const reducer = forgotPasswordReducers(initialState, { | ||
type: FORGOT_PASSWORD_FAIL, | ||
message: { payload: { sendEmail: 'raymondsdf' } } | ||
}); | ||
expect(reducer).toHaveProperty('message'); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/feature/Reset Password/forgot password/forgotPasswordAction.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import axios from 'axios'; | ||
import { toast } from 'react-toastify'; | ||
import { BACKEND_URL } from '../../../app/common/config/appConfig'; | ||
import { FORGOT_PASSWORD_SUCCESS, FORGOT_PASSWORD_FAIL } from './forgotPasswordActionTypes'; | ||
|
||
const forgotPasswordAction = (email) => async (dispatch) => { | ||
const userMessage = { | ||
email, | ||
}; | ||
try { | ||
const res = await axios.post( | ||
`${BACKEND_URL}/users/send-email`, | ||
userMessage, | ||
); | ||
const { message } = res.data; | ||
toast.success(message, { position: toast.POSITION.TOP_CENTER }); | ||
dispatch({ | ||
type: FORGOT_PASSWORD_SUCCESS, | ||
payload: res.data, | ||
|
||
}); | ||
} catch (error) { | ||
const erroMessage = (await error.response) ? error.response.data.error : 'Network Error'; | ||
toast.error(erroMessage, { position: toast.POSITION.TOP_CENTER }); | ||
dispatch({ type: FORGOT_PASSWORD_FAIL, payload: erroMessage }); | ||
} | ||
}; | ||
|
||
export default forgotPasswordAction; |
2 changes: 2 additions & 0 deletions
2
src/feature/Reset Password/forgot password/forgotPasswordActionTypes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const FORGOT_PASSWORD_SUCCESS = 'FORGOT_PASSWORD_SUCCESS'; | ||
export const FORGOT_PASSWORD_FAIL = 'FORGOT_PASSWORD_FAIL'; |
22 changes: 22 additions & 0 deletions
22
src/feature/Reset Password/forgot password/forgotPasswordReducers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { FORGOT_PASSWORD_SUCCESS, FORGOT_PASSWORD_FAIL } from './forgotPasswordActionTypes'; | ||
|
||
const initialState = { | ||
message: '', | ||
}; | ||
export default function (state = initialState, action) { | ||
const { type, payload } = action; | ||
switch (type) { | ||
case FORGOT_PASSWORD_SUCCESS: | ||
return { | ||
...state, | ||
message: payload, | ||
}; | ||
case FORGOT_PASSWORD_FAIL: | ||
return { | ||
...state, | ||
message: payload, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
Oops, something went wrong.