Skip to content
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

Merged
merged 1 commit into from
Nov 5, 2018
Merged

Conversation

MuhanguziDavid
Copy link
Contributor

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?

  • Run npm install to install all dependencies
  • Run npm start
  • Enter the url http://localhost:3000/signup in your browser.
  • Enter user details in the registration form and click submit

What are the relevant pivotal tracker stories?

#160609513

Any background context you want to add?

N/A

Screenshots

registerform

import { toast } from 'react-toastify';
import { REGISTER_USER_SUCCESS, REGISTER_USER_ERROR } from './types';

export const fetchUsers = (postData) => dispatch => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@RonKbS
Copy link
Contributor

RonKbS commented Nov 2, 2018

The circleci and travis tests are failing, @MuhanguziDavid.
It may be because you have not included some packages in the package.json file.

@MuhanguziDavid MuhanguziDavid force-pushed the ft-register-users-160609513 branch 3 times, most recently from dac6dcb to 5828f63 Compare November 3, 2018 20:55
@coveralls
Copy link

coveralls commented Nov 3, 2018

Pull Request Test Coverage Report for Build 129

  • 39 of 39 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.5%) to 98.507%

Totals Coverage Status
Change from base Build 95: -1.5%
Covered Lines: 57
Relevant Lines: 57

💛 - Coveralls

.then((response) => {
localStorage.setItem('auth_token', response.data.user.auth_token);
dispatch({ type: REGISTER_USER_SUCCESS, payload: true });
toast.success('Signup successful', { autoClose: false });
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

@mendozabree mendozabree left a 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

toast.success('Signup successful', { autoClose: false });
})
.catch((error) => {
let emailKey = 'Email: ';
Copy link
Contributor

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>
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Contributor Author

@MuhanguziDavid MuhanguziDavid Nov 5, 2018

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

import { REGISTER_USER_SUCCESS, REGISTER_USER_ERROR } from './types';

export const fetchUsers = (postData) => dispatch => {
axios
Copy link
Contributor

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);
Copy link
Contributor

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 () => {
Copy link
Contributor

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.

@@ -0,0 +1,25 @@
import { REGISTER_USER_SUCCESS, REGISTER_USER_ERROR } from '../actions/types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userReducer not registerUserReducer

@@ -0,0 +1,35 @@
import axios from 'axios';
Copy link
Contributor

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 },
Copy link
Contributor

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', () => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@dondrzzy dondrzzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor

@MuhanguziDavid
Copy link
Contributor Author

MuhanguziDavid commented Nov 5, 2018

Thanks for the feedback, I have refactored accordingly.

@MuhanguziDavid MuhanguziDavid force-pushed the ft-register-users-160609513 branch 9 times, most recently from f08746e to cbf40ad Compare November 5, 2018 17:11
- enable user signup from front end

[Delivers #160609513]
@dondrzzy dondrzzy merged commit 2397d6d into develop Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants