Skip to content

Commit

Permalink
Merge d0e671e into c2e80b5
Browse files Browse the repository at this point in the history
  • Loading branch information
chiboycalix authored Sep 12, 2019
2 parents c2e80b5 + d0e671e commit 65fc36a
Show file tree
Hide file tree
Showing 32 changed files with 909 additions and 143 deletions.
196 changes: 124 additions & 72 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"async-wait-until": "^1.2.4",
"axios-mock-adapter": "^1.17.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
Expand All @@ -110,6 +111,7 @@
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"fetch-mock": "^7.3.9",
"file-loader": "^4.2.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^3.0.4",
Expand All @@ -124,6 +126,7 @@
"nock": "^11.3.1",
"node-sass": "^4.12.0",
"nyc": "^14.1.1",
"redux-api-middleware": "^3.0.1",
"redux-mock-store": "^1.5.3",
"sass-loader": "^7.3.1",
"sinon": "^7.4.2",
Expand All @@ -133,4 +136,4 @@
"webpack-dev-server": "^3.8.0",
"webpack-merge": "^4.2.1"
}
}
}
3 changes: 0 additions & 3 deletions src/actions/Articles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const getHomePageArticles = () => async dispatch => {
});
} catch (err) {
// eslint-disable-next-line no-console
// console.log(err);
}
};

Expand All @@ -35,7 +34,6 @@ export const getArticle = () => async dispatch => {
});
} catch (err) {
// eslint-disable-next-line no-console
// console.log(err);
}
};

Expand All @@ -50,7 +48,6 @@ export const getEditorsChoice = () => async dispatch => {
});
} catch (err) {
// eslint-disable-next-line no-console
// console.log(err);
}
};

Expand Down
44 changes: 44 additions & 0 deletions src/actions/__tests__/followActions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import moxios from 'moxios';
import { makeMockStore } from '@Utils/index';
import {
followUser,
followUserSuccess,
followUserFailure,
followUserStart,
} from '../followActions';

const store = makeMockStore({});


describe('testing redux actions', () => {
beforeEach(() => {
moxios.install();
});
afterEach(() => {
moxios.uninstall();
});
it('should follow a user', async () => {
const res = await store.dispatch(followUserStart());
expect(res.type).toEqual('FOLLOW_USER_START');
});

it('should follow a user', async () => {
const res = await store.dispatch(followUserSuccess());
expect(res.type).toEqual('FOLLOW_USER_SUCCESS');
});

it('should follow a user', async () => {
const res = await store.dispatch(followUserFailure());
expect(res.type).toEqual('FOLLOW_USER_FAILURE');
});

it('should follow a user', async () => {
const res = await store.dispatch(followUser());
expect(res.type).toEqual('FOLLOW_USER_FAILURE');
});
it('should follow a user', async () => {
const res = await store.getActions();
expect(res[1].type).toEqual('FOLLOW_USER_SUCCESS');
expect(res[1].payload).toEqual(undefined);
});
});
18 changes: 9 additions & 9 deletions src/actions/__tests__/profileAction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const mock = new MockAdapter(axios);
describe('profile action', () => {
localStorage.setItem('haven', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjUsInVzZXJuYW1lIjoibm9ub2p1IiwiZW1haWwiOiJhYkBnbWFpbC5jb20iLCJpYXQiOjE1Njc1MzMwMTcsImV4cCI6MTU2NzYxOTQxN30.YYgbnLLX0hRzxSpSPLR5wj04lzJnTjUKBZlRh_-T9CI');

it('success', () => {
it('success 1', () => {
const expectedAction = {
type: 'GET_PROFILE_SUCCESS',
payload: {
Expand All @@ -30,14 +30,14 @@ describe('profile action', () => {
expect(getProfileSuccess(expectedAction.payload)).toEqual(expectedAction);
});

it('success', () => {
it('success 2', () => {
const expectedAction = {
type: 'GET_PROFILE_START',
};
expect(getProfileStart()).toEqual(expectedAction);
});

it('test', () => {
it('error 1', () => {
mock.onGet('https://a-haven-staging.herokuapp.com/api/v1/profiles/',
{
params: { username: 'nono' },
Expand All @@ -51,13 +51,13 @@ describe('profile action', () => {
return store.dispatch(getProfile()).then((data) => {
const expectedAction = {
type: 'GET_PROFILE_FAILURE',
error: { error: 'User not found', status: 404 },
error: { error: 'Authorization error', status: 401 },
};
expect(data).toEqual(expectedAction);
});
});

it('test', () => {
it('error 2', () => {
localStorage.setItem('haven', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjUsInVzZXJuYW1lIjoibm9ub2p1IiwiZW1haWwiOiJhYkBnbWFpbC5jb20iLCJpYXQiOjE1Njc1MzMwMTcsImV4cCI6MTU2NzYxOTQxN30.YYgbnLLX0hRzxSpSPLR5wj04lzJnTjUKBZlRh_-T9CI');
mock.onPut('https://a-haven-staging.herokuapp.com/api/v1/user/').reply(200, {
user: [{ id: 2, email: 'nonso@mail.com' },
Expand All @@ -80,7 +80,7 @@ describe('profile action', () => {
afterEach(() => {
mock.reset();
});
it('success', () => {
it('new describe 1', () => {
const expectedAction = {
type: 'GET_ARTICLE_SUCCESS',
payload: {
Expand All @@ -91,14 +91,14 @@ describe('profile action', () => {
expect(getArticlesSuccess(expectedAction.payload)).toEqual(expectedAction);
});

it('success', () => {
it('new describe 2', () => {
const expectedAction = {
type: 'GET_ARTICLE_START',
};
expect(getArticlesStart()).toEqual(expectedAction);
});

it('test', () => {
it('new describe 3', () => {
const store = mockStore({ });
store.dispatch(getArticlesStart);
return store.dispatch(getArticles()).then((data) => {
Expand All @@ -111,7 +111,7 @@ describe('profile action', () => {
});
});

describe('Async action creators', () => {
describe('another describe block', () => {
it('Should create SIGN_IN_USER_SUCCEEDED when signIn user has been done', async () => {
const article = {
title: 'image title',
Expand Down
44 changes: 44 additions & 0 deletions src/actions/__tests__/unfollowActions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import moxios from 'moxios';
import { makeMockStore } from '@Utils/index';
import {
unFollowUser,
unfollowUserSuccess,
unfollowUserFailure,
unfollowUserStart,
} from '../unfollowActions';

const store = makeMockStore({});


describe('testing redux actions', () => {
beforeEach(() => {
moxios.install();
});
afterEach(() => {
moxios.uninstall();
});
it('should follow a user', async () => {
const res = await store.dispatch(unfollowUserStart());
expect(res.type).toEqual('UNFOLLOW_USER_START');
});

it('should follow a user', async () => {
const res = await store.dispatch(unfollowUserSuccess());
expect(res.type).toEqual('UNFOLLOW_USER_SUCCESS');
});

it('should follow a user', async () => {
const res = await store.dispatch(unfollowUserFailure());
expect(res.type).toEqual('UNFOLLOW_USER_FAILURE');
});

it('should follow a user', async () => {
const res = await store.dispatch(unFollowUser());
expect(res.type).toEqual('UNFOLLOW_USER_FAILURE');
});
it('should follow a user', async () => {
const res = await store.getActions();
expect(res[1].type).toEqual('UNFOLLOW_USER_SUCCESS');
expect(res[1].payload).toEqual(undefined);
});
});
27 changes: 27 additions & 0 deletions src/actions/followActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as types from '@Actions/types';
import { axiosInstance } from '@Utils/';

export const followUserStart = () => ({
type: types.FOLLOW_USER_START,
});

export const followUserSuccess = (payload) => ({
type: types.FOLLOW_USER_SUCCESS,
payload,
});

export const followUserFailure = (error) => ({
type: types.FOLLOW_USER_FAILURE,
error,
});


export const followUser = (username) => async (dispatch) => {
dispatch(followUserStart());
try {
const response = await axiosInstance.post(`/profiles/${username}/follow`);
return dispatch(followUserSuccess(response.data.profile));
} catch (error) {
return dispatch(followUserFailure(error.response.data));
}
};
19 changes: 14 additions & 5 deletions src/actions/profileAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ export const getArticlesFailure = (error) => ({
error,
});

export const getProfile = () => async (dispatch) => {
export const getProfile = (username = null) => async (dispatch) => {
dispatch(getProfileStart());
try {
const token = jwtDecode(localStorage.getItem('haven'));
const response = await axiosInstance.get(`/profiles/${token.username}`);
if (username) {
const response = await axiosInstance.get(`/profiles/${username}/`);
return dispatch(getProfileSuccess(response.data.profile));
}
const response = await axiosInstance.get('/user');
return dispatch(getProfileSuccess(response.data.profile));
} catch (error) {
return dispatch(getProfileFailure(error.response.data));
Expand All @@ -63,19 +66,25 @@ export const editProfile = (payload) => async (dispatch) => {
const response = await axiosInstance.put('/user', payload);
localStorage.setItem('haven', response.data.profile.token);
swal({
title: 'Edit User Profile',
text: 'Your Profile has been successfully Edited',
icon: 'success',
timer: 3000,
});
return dispatch(editProfileSuccess(response.data.profile));
} catch (error) {
return dispatch(editProfileFailure(error.response.data));
}
};

export const getArticles = () => async (dispatch) => {
export const getArticles = (authorId = null) => async (dispatch) => {
let id;
dispatch(getArticlesStart());
try {
if (authorId) {
id = authorId;
const response = await axiosInstance.get(`/articles/?authorId=${id}`);
return dispatch(getArticlesSuccess(response.data.articles));
}
const token = jwtDecode(localStorage.getItem('haven'));
const response = await axiosInstance.get(`/articles/?authorId=${token.id}`);
return dispatch(getArticlesSuccess(response.data.articles));
Expand Down
9 changes: 9 additions & 0 deletions src/actions/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const MODAL_OPEN = 'MODAL_OPEN';
export const MODAL_CLOSE = 'MODAL_CLOSE';
export const LOADING = 'LOADING';
export const NOT_LOADING = 'NOT_LOADING';

export const GET_PROFILE_START = 'GET_PROFILE_START';
export const GET_PROFILE_SUCCESS = 'GET_PROFILE_SUCCESS';
export const GET_PROFILE_FAILURE = 'GET_PROFILE_FAILURE';
Expand All @@ -27,3 +28,11 @@ export const UPDATE_SEARCHQUERY = 'UPDATE_SEARCHQUERY';
export const UPDATE_PAGENUMBER = 'UPDATE_PAGENUMBER';
export const CREATE_ARTICLE = 'CREATE_ARTICLE';
export const READ_ARTICLE = 'READ_ARTICLE';

export const FOLLOW_USER_START = 'FOLLOW_USER_START';
export const FOLLOW_USER_SUCCESS = 'FOLLOW_USER_SUCCESS';
export const FOLLOW_USER_FAILURE = 'FOLLOW_USER_FAILURE';

export const UNFOLLOW_USER_START = 'UNFOLLOW_USER_START';
export const UNFOLLOW_USER_SUCCESS = 'UNFOLLOW_USER_SUCCESS';
export const UNFOLLOW_USER_FAILURE = 'UNFOLLOW_USER_FAILURE';
27 changes: 27 additions & 0 deletions src/actions/unfollowActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as types from '@Actions/types';
import { axiosInstance } from '@Utils/';

export const unfollowUserStart = () => ({
type: types.UNFOLLOW_USER_START,
});

export const unfollowUserSuccess = (payload) => ({
type: types.UNFOLLOW_USER_SUCCESS,
payload,
});

export const unfollowUserFailure = (error) => ({
type: types.UNFOLLOW_USER_FAILURE,
error,
});


export const unFollowUser = (username) => async (dispatch) => {
dispatch(unfollowUserStart());
try {
const response = await axiosInstance.delete(`/profiles/${username}/follow`);
return dispatch(unfollowUserSuccess(response.data.profile));
} catch (error) {
return dispatch(unfollowUserFailure(error.response.data));
}
};
3 changes: 2 additions & 1 deletion src/components/Forms/PasswordRequest/PasswordRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export class PasswordRequest extends Component {
handleClick={this.handleSubmit}
style={{
height: '45px',
width: '300px',
width: '90%',
marginLeft: '5%',
color: '#ffc700',
backgroundColor: '#000',
borderRadius: '0',
Expand Down
3 changes: 2 additions & 1 deletion src/components/Forms/SignIn/SignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export class SignIn extends Component {
id="signin"
style={{
height: '45px',
width: '300px',
width: '90%',
marginLeft: '5%',
color: '#ffc700',
backgroundColor: '#000',
borderRadius: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ exports[`test social media sign in should click the google signin button 1`] = `
"borderRadius": "0",
"color": "#ffc700",
"height": "45px",
"width": "300px",
"marginLeft": "5%",
"width": "90%",
}
}
type="submit"
Expand Down
3 changes: 2 additions & 1 deletion src/components/Forms/SignUp/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ export class SignUp extends Component {
type="submit"
style={{
height: '45px',
width: '300px',
width: '90%',
marginLeft: '5%',
color: '#ffc700',
backgroundColor: '#000',
borderRadius: '0',
Expand Down
Loading

0 comments on commit 65fc36a

Please sign in to comment.