-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(users): user registration #13
Conversation
src/actions/registerUserActions.js
Outdated
import { toast } from 'react-toastify'; | ||
import { REGISTER_USER_SUCCESS, REGISTER_USER_ERROR } from './types'; | ||
|
||
export const fetchUsers = (postData) => dispatch => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on implementing this feature, @MuhanguziDavid.
This block of code is unclear to me. Is it necessary to have two arrow functions like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RonKbS , yes, it is necessary. Like having one function within another.
The circleci and travis tests are failing, @MuhanguziDavid. |
dac6dcb
to
5828f63
Compare
Pull Request Test Coverage Report for Build 129
💛 - Coveralls |
src/actions/registerUserActions.js
Outdated
.then((response) => { | ||
localStorage.setItem('auth_token', response.data.user.auth_token); | ||
dispatch({ type: REGISTER_USER_SUCCESS, payload: true }); | ||
toast.success('Signup successful', { autoClose: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @MuhanguziDavid! I am impressed with your test coverage!
You should consider changing the autoClose
functionality.
Something of the sort { autoClose: 3500, hideProgressBar: true }
the latter part removes the default progress bar. The same toast change applies to the error
toast on line 33.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autoClose functionality has been changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MuhanguziDavid, good work with testing the component and the naming conventions.
Though you missed one, consider renaming the component test file, for example, a component named CreateArticle.js
would have its corresponding file named CreateArticle.test.js
src/actions/registerUserActions.js
Outdated
toast.success('Signup successful', { autoClose: false }); | ||
}) | ||
.catch((error) => { | ||
let emailKey = 'Email: '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a for-in loop to check the errors object. Link
const { email, password, username } = this.state; | ||
return ( | ||
<div className="registerForm"> | ||
<h1>Register</h1> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get a few ideas from here
|
||
const mapStateToProps = state => ({ | ||
registerUserSuccess: state.user.registerUserSuccess, | ||
registerUserError: state.user.registerUserError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left that there in the event that errors are shown within the form
src/actions/registerUserActions.js
Outdated
import { REGISTER_USER_SUCCESS, REGISTER_USER_ERROR } from './types'; | ||
|
||
export const fetchUsers = (postData) => dispatch => { | ||
axios |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the axios Instance
here. Link
const passwordKey = 'Password: '; | ||
|
||
beforeEach(() => { | ||
mockAdapter = new MockAdapter(axios); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use mock instead of mockAdapter
store = mockStore({}); | ||
}); | ||
|
||
it('should register a user', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should be in the directory tests/actions/userActions
.
src/reducers/registerUserReducer.js
Outdated
@@ -0,0 +1,25 @@ | |||
import { REGISTER_USER_SUCCESS, REGISTER_USER_ERROR } from '../actions/types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userReducer
not registerUserReducer
src/actions/registerUserActions.js
Outdated
@@ -0,0 +1,35 @@ | |||
import axios from 'axios'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userActions
not registerUserActions
it('should not register a user without a valid username', async () => { | ||
const response_data = { | ||
token: 'my secret token', | ||
errors: { email: ['This field may not be blank.'], password: ['This field may not be blank.'], username: null }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Email value should never be an array of a string. Get the 0 index value.
expect(fetchUsers.mock.calls[2][0]).toEqual({ user: { email: 'user100@gmail.com', password: 'Abc12345', username: 'user100' } }); | ||
}); | ||
|
||
it('should redirect on successful login', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this test doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had put it there to test whether there is redirection on successful user signup, the test has now been added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor
5828f63
to
bfb8e10
Compare
Thanks for the feedback, I have refactored accordingly. |
f08746e
to
cbf40ad
Compare
- enable user signup from front end [Delivers #160609513]
cbf40ad
to
5a420ae
Compare
What does this PR do?
It enables users to signup using Authors Heaven front end.
Description of tasks to be completed?
Currently, a user cannot signup to Authors Heaven using the front end
This PR adds functionality to allow users to signup to Authors Heaven using the front end
How should this be manually tested?
npm install
to install all dependenciesnpm start
http://localhost:3000/signup
in your browser.submit
What are the relevant pivotal tracker stories?
#160609513
Any background context you want to add?
N/A
Screenshots