Skip to content

Commit

Permalink
Merge a5125b9 into 337bbac
Browse files Browse the repository at this point in the history
  • Loading branch information
dnuwa committed Dec 19, 2018
2 parents 337bbac + a5125b9 commit 15f38e3
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 43 deletions.
7 changes: 3 additions & 4 deletions src/actions/articleActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';
import ACTION_TYPE from './actionTypes';
import APP_URL from '../utils/constants';

export const fetchArticlesSuccess = articles => ({
type: ACTION_TYPE.FETCH_ARTICLES_SUCCESS,
Expand All @@ -17,7 +16,7 @@ export const showErrorAction = payload => ({
payload, // error message
});

export const fetchArticlesThunk = () => dispatch => axios.get(`${APP_URL}/articles`)
export const fetchArticlesThunk = () => dispatch => axios.get('https://ah-backend-thanos-staging.herokuapp.com/api/articles')
.then((response) => {
dispatch(fetchArticlesSuccess(response.data.results));
})
Expand All @@ -37,7 +36,7 @@ export const getLikeStatusAction = payload => ({
});

export const getArticleThunk = articleId => (dispatch) => {
const url = `${APP_URL}/articles/${articleId}`;
const url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}`;
return axios.get(url)
.then((response) => {
dispatch(getArticleAction(response.data.results));
Expand All @@ -52,7 +51,7 @@ export const getArticleThunk = articleId => (dispatch) => {
};

export const getLikeStatusThunk = ({ articleId, token }) => (dispatch, getState) => {
const url = `${APP_URL}/articles/${articleId}/like_status`;
const url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}/like_status`;
return axios.get(url, { headers: { Authorization: `Token ${token}` } })
.then((response) => {
const obj = response.data.results.filter(
Expand Down
3 changes: 1 addition & 2 deletions src/actions/commentActions/commentAction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
AllComments, CommentInput, PostComment, allCommentsFail,
allCommentsSuccessful, postCommentFail, postCommentSuccessful,
} from './index';
import APP_URL from '../../utils/constants';

const mockStore = configureMockStore([thunk]);

Expand All @@ -31,7 +30,7 @@ describe('Test Comment actions', () => {
payload: data,
}));
const articleId = 1;
const url = `${APP_URL}/articles/${articleId}/comments`;
const url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}/comments`;

const request = () => (
moxios.stubRequest(url, Notfound())
Expand Down
5 changes: 2 additions & 3 deletions src/actions/commentActions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';
import action from './actionTypes';
import APP_URL from '../../utils/constants';

export const allCommentsSuccessful = data => ({
type: action.GET_ALL_COMMENTS_SUCCESSFUL,
Expand Down Expand Up @@ -28,7 +27,7 @@ export const postCommentFail = data => ({
});

export const AllComments = articleId => (dispatch) => {
const url = `${APP_URL}/articles/${articleId}/comments`;
const url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}/comments`;
return axios.get(url)
.then((response) => { dispatch(allCommentsSuccessful(response.data)); })
.catch((error) => { dispatch(allCommentsFail(error.response)); });
Expand All @@ -41,7 +40,7 @@ export const PostComment = (articleId, data) => (dispatch) => {
Authorization: `Token ${token}`,
},
};
const url = `${APP_URL}/articles/${articleId}/comments`;
const url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}/comments`;
return axios.post(url, data, headers)
.then((response) => { dispatch(postCommentSuccessful(response.data.results)); })
.catch((error) => {
Expand Down
3 changes: 1 addition & 2 deletions src/actions/likedislikeActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';
import actionTypes from './actionTypes';
import APP_URL from '../utils/constants';

export const likeDislikeArticleAction = payload => ({
type: actionTypes.LIKEDISLIKE_ARTICLE,
Expand All @@ -9,7 +8,7 @@ export const likeDislikeArticleAction = payload => ({

export const likeDislikeArticleThunk = likeObj => (dispatch) => {
const { articleId, likeDislikeStatus, token } = likeObj;
const url = `${APP_URL}/articles/${articleId}/like_status`;
const url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}/like_status`;
const headerValue = { headers: { Authorization: `Token ${token}` } };
const payload = res => ({
results: res.data.results,
Expand Down
3 changes: 1 addition & 2 deletions src/actions/loginActions/loginAction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';
import ACTION_TYPE from '../actionTypes';
import APP_URL from '../../utils/constants';

export const loginSuccess = response => ({
type: ACTION_TYPE.USER_LOGIN_SUCCESS,
Expand All @@ -18,7 +17,7 @@ export const loginThunk = data => (dispatch) => {
...data,
},
};
return axios.post(`${APP_URL}/users/login`, userdata)
return axios.post('https://ah-backend-thanos-staging.herokuapp.com/api/users/login', userdata)
.then((res) => {
dispatch(loginSuccess(res.data.results));
}).catch((error) => {
Expand Down
7 changes: 3 additions & 4 deletions src/actions/loginActions/loginActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { loginSuccess, loginThunk, loginFailure } from './loginAction';
import ACTION_TYPE from '../actionTypes';
import APP_URL from '../../utils/constants';

describe('Login Actions tests', () => {
const mockStore = configureMockStore([thunk]);
Expand Down Expand Up @@ -39,13 +38,13 @@ describe('Login Actions tests', () => {
})
);
test('Login successfull', () => {
moxios.stubRequest(`${APP_URL}/users/login`, loginSuccessData);
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/users/login', loginSuccessData);
const expectedtActions = { type: ACTION_TYPE.USER_LOGIN_SUCCESS };
const store = mockStore({});
returnExpect(store, expectedtActions);
});
test('Login failed', () => {
moxios.stubRequest(`${APP_URL}/users/login`, {
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/users/login', {
status: 400,
response: { error: 'Not found' },
});
Expand All @@ -57,7 +56,7 @@ describe('Login Actions tests', () => {
returnExpect(store, expectedtActions);
});
test('Login unsuccessfull', () => {
moxios.stubRequest(`${APP_URL}/users/login`, {
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/users/login', {
status: 400,
errors: {
results: { errors: ['Some error here'] },
Expand Down
5 changes: 2 additions & 3 deletions src/actions/ratingActions/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import axios from 'axios';
import ACTION_TYPE from '../actionTypes';
import APP_URL from '../../utils/constants';

export const ratingSuccess = rate => ({
type: ACTION_TYPE.GET_RATING_SUCCESS,
payload: rate,
});

export const fetchRatingThunk = articleId => dispatch => axios.get(`${APP_URL}/articles/${articleId}`)
export const fetchRatingThunk = articleId => dispatch => axios.get(`https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}`)
.then((response) => {
dispatch(ratingSuccess(response.data.results));
});
Expand All @@ -29,7 +28,7 @@ export const postRatingData = rate => ({

const tok = localStorage.getItem('token');
export const postRating = (articleId, data) => (dispatch) => {
const url = `${APP_URL}/articles/${articleId}/rating`;
const url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${articleId}/rating`;
const token = `Token ${tok}`;
const headers = {
headers: { Authorization: token },
Expand Down
18 changes: 12 additions & 6 deletions src/actions/ratingActions/ratingActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import moxios from 'moxios';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import {
ratingSuccess, fetchRatingThunk, postRatingSuccess, postRating,
ratingSuccess, fetchRatingThunk, postRatingSuccess, postRating, postRatingFailed,
} from './index';
import ACTION_TYPE from '../actionTypes';
import APP_URL from '../../utils/constants';


describe('Login Actions tests', () => {
let store;
Expand All @@ -27,6 +25,14 @@ describe('Login Actions tests', () => {
// import and pass your custom axios instance to this method
moxios.uninstall();
});
it('should return an error on unsuccessful rating of an article', () => {
const errorMessage = { error: 'Some error' };
const expectedAction = {
type: ACTION_TYPE.POST_RATING_FAILED,
payload: errorMessage,
};
expect(postRatingFailed(errorMessage)).toEqual(expectedAction);
});
test('Successful get and post rating action', () => {
expect(ratingSuccess(rate)).toEqual(expect.objectContaining(
actionTypesData(ACTION_TYPE.GET_RATING_SUCCESS, rate),
Expand All @@ -40,7 +46,7 @@ describe('Login Actions tests', () => {
responseText: response,
});
test('get rate successfull', () => {
moxios.stubRequest(`${APP_URL}/articles/7`, statusData(200, { message: 'ok' }));
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/articles/7', statusData(200, { message: 'ok' }));
store.dispatch(fetchRatingThunk(7)).then(() => {
expect(store.getActions()).toEqual(expect.objectContaining(
[{
Expand All @@ -50,15 +56,15 @@ describe('Login Actions tests', () => {
});
});
test('get rate successfull', () => {
moxios.stubRequest(`${APP_URL}/articles/7/rating`, statusData(200, { message: 'ok' }));
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/articles/7/rating', statusData(200, { message: 'ok' }));
store.dispatch(postRating(7)).then(() => {
expect(store.getActions()).toEqual(expect.objectContaining(
actionTypesData(ACTION_TYPE.POST_RATING_SUCCESS, { message: 'ok' }),
));
});
});
test('get rate Failed', () => {
moxios.stubRequest(`${APP_URL}/articles/7/rating`, {
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/articles/7/rating', {
status: 400,
error: { error: 'Rating failed' },
});
Expand Down
17 changes: 13 additions & 4 deletions src/actions/tests/articleActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
fetchArticlesSuccess,
fetchArticlesFailure,
fetchArticlesThunk,
showErrorAction,
} from '../articleActions';
import ACTION_TYPE from '../actionTypes';
import APP_URL from '../../utils/constants';

describe('Article component', () => {
let store;
Expand All @@ -21,7 +21,7 @@ describe('Article component', () => {
sampleId = 1;
const mockStore = configureMockStore([reduxThunk]);
store = mockStore({});
url = `${APP_URL}/articles/${sampleId}`;
url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${sampleId}`;
});

afterEach(() => {
Expand All @@ -31,7 +31,7 @@ describe('Article component', () => {
it('should handle fetchArticlesFailure', () => {
const errorMessage = 'Check your internet conectivity';
moxios.stubRequest(
`${APP_URL}/articles`,
'https://ah-backend-thanos-staging.herokuapp.com/api/articles',
{
status: 400,
response: {
Expand All @@ -58,7 +58,7 @@ describe('Article component', () => {
],
};
moxios.stubRequest(
`${APP_URL}/articles`,
'https://ah-backend-thanos-staging.herokuapp.com/api/articles',
{
status: 200,
response: mockData,
Expand All @@ -85,6 +85,15 @@ describe('Article component', () => {
expect(fetchArticlesSuccess(article)).toEqual(expectedAction);
});

it('should return an error on unsuccessful fetching of all articles', () => {
const payload = { error: 'Some error' };
const expectedAction = {
type: ACTION_TYPE.SHOW_ERROR,
payload,
};
expect(showErrorAction(payload)).toEqual(expectedAction);
});

it('should create an action on failure to fetch all articles', () => {
const msg = 'no internet connection';

Expand Down
5 changes: 2 additions & 3 deletions src/actions/tests/authactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import moxios from 'moxios';
import { socialUserLogin } from '../userActions';
import ACTION_TYPES from '../actionTypes';
import { SocialLogin } from '../actionCreators';
import APP_URL from '../../utils/constants';

describe('social auth actions', () => {
let store;
Expand Down Expand Up @@ -49,7 +48,7 @@ describe('social auth actions', () => {
const token = 'some-token';
const url = 'google-url';

moxios.stubRequest(`${APP_URL}/${url}/${token}`, {
moxios.stubRequest(`https://ah-backend-thanos-staging.herokuapp.com/api/${url}/${token}`, {
status: 200,
method: 'post',
response: {
Expand All @@ -69,7 +68,7 @@ describe('social auth actions', () => {
const token = 'some-token';
const url = 'google-url';

moxios.stubRequest(`${APP_URL}/${url}/${token}`, {
moxios.stubRequest(`https://ah-backend-thanos-staging.herokuapp.com/api/${url}/${token}`, {
status: 400,
});

Expand Down
3 changes: 1 addition & 2 deletions src/actions/tests/likedislikeActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import thunk from 'redux-thunk';
import moxios from 'moxios';
import actionTypes from '../actionTypes';
import { likeDislikeArticleThunk } from '../likedislikeActions';
import APP_URL from '../../utils/constants';

const mockStore = configureMockStore([thunk]);

Expand All @@ -16,7 +15,7 @@ describe('Like/Dislike Actions', () => {
moxios.install();
store = mockStore({});
sampleId = 1;
url = `${APP_URL}/articles/${sampleId}/like_status`;
url = `https://ah-backend-thanos-staging.herokuapp.com/api/articles/${sampleId}/like_status`;
});

afterEach(() => {
Expand Down
5 changes: 2 additions & 3 deletions src/actions/tests/userActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import actionTypes from '../actionTypes';
import {
signupSuccessful, signupFail, getUserInput, userSignup,
} from '../userActions';
import APP_URL from '../../utils/constants';

const mockStore = configureMockStore([thunk]);

Expand Down Expand Up @@ -51,7 +50,7 @@ describe('Test User actions', () => {
});

test('UserSignup Action Pass', () => {
moxios.stubRequest(`${APP_URL}/users`, {
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/users', {
status: 200,
responseText: {
email: 'johndoe@example.com',
Expand All @@ -71,7 +70,7 @@ describe('Test User actions', () => {
});

test('UserSignup Action Fail', () => {
moxios.stubRequest(`${APP_URL}/users`, {
moxios.stubRequest('https://ah-backend-thanos-staging.herokuapp.com/api/users', {
status: 400,
responseText: {
email: ['user with this email already exists'],
Expand Down
5 changes: 2 additions & 3 deletions src/actions/userActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios from 'axios';
import swal from 'sweetalert2';
import actionTypes from './actionTypes';
import APP_URL from '../utils/constants';
import { SocialLogin, LogIn, socialLoginFailure } from './actionCreators';

export const signupSuccessful = response => ({
Expand All @@ -22,7 +21,7 @@ export const getUserInput = payload => ({
export const userSignup = freshUser => (dispatch) => {
swal.showLoading();
return axios
.post(`${APP_URL}/users`, freshUser)
.post('https://ah-backend-thanos-staging.herokuapp.com/api/users', freshUser)
.then((response) => {
dispatch(
signupSuccessful({
Expand All @@ -42,7 +41,7 @@ export const userSignup = freshUser => (dispatch) => {
export const socialUserLogin = (url, token) => (dispatch) => {
dispatch(SocialLogin(true));
return axios
.post(`${APP_URL}/${url}/${token}`)
.post(`https://ah-backend-thanos-staging.herokuapp.com/api/${url}/${token}`)
.then((response) => {
localStorage.setItem('token', response.data.results.token);
localStorage.setItem('username', response.data.results.username);
Expand Down
2 changes: 0 additions & 2 deletions src/utils/constants.js

This file was deleted.

0 comments on commit 15f38e3

Please sign in to comment.