-
Notifications
You must be signed in to change notification settings - Fork 4
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
34 changed files
with
583 additions
and
146 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
package-lock.json | ||
/coverage | ||
yarn.lock | ||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="description" content="Authors Haven; A Social platform for the creative at heart"> | ||
<meta name="keywords" content="author, blog, write"> | ||
<meta name="author" content="Team Thanos: Andela Cohort 11"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta | ||
name="description" | ||
content="Authors Haven; A Social platform for the creative at heart" | ||
/> | ||
<meta name="keywords" content="author, blog, write" /> | ||
<meta name="author" content="Team Thanos: Andela Cohort 11" /> | ||
|
||
<title>Authors Haven</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
</head> | ||
<body> | ||
<noscript> You need to enable JavaScript to run this app. </noscript> | ||
|
||
<div id="root"></div> | ||
</body> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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, | ||
articles, | ||
}); | ||
|
||
export const fetchArticlesFailure = errorMessage => ({ | ||
type: ACTION_TYPE.FETCH_ARTICLES_FAILURE, | ||
errorMessage, | ||
}); | ||
|
||
const fetchArticlesThunk = () => dispatch => axios.get(`${APP_URL}/articles`) | ||
.then((response) => { | ||
dispatch(fetchArticlesSuccess(response.data.results)); | ||
}) | ||
.catch(() => { | ||
dispatch(fetchArticlesFailure('Check your internet conectivity')); | ||
}); | ||
|
||
export default fetchArticlesThunk; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as moxios from 'moxios'; | ||
import configurestore from 'redux-mock-store'; | ||
import reduxThunk from 'redux-thunk'; | ||
import fetchArticlesThunk, { | ||
fetchArticlesSuccess, | ||
fetchArticlesFailure, | ||
} from '../articleActions'; | ||
import ACTION_TYPE from '../actionTypes'; | ||
import APP_URL from '../../utils/constants'; | ||
|
||
const middlewares = [reduxThunk]; | ||
const mockStore = configurestore(middlewares); | ||
let store; | ||
describe('get articles component', () => { | ||
beforeEach(() => { | ||
moxios.install(); | ||
store = mockStore(); | ||
}); | ||
|
||
afterEach(() => { | ||
moxios.uninstall(); | ||
}); | ||
|
||
it('should handel fetchArticlesFailure', () => { | ||
const errorMessage = 'Check your internet conectivity'; | ||
moxios.stubRequest( | ||
`${APP_URL}/articles`, | ||
{ | ||
status: 400, | ||
response: { | ||
errors: { | ||
error: '', | ||
}, | ||
}, | ||
}, | ||
); | ||
store.clearActions(); | ||
const expectedActions = [{ errorMessage, type: 'FETCH_ARTICLES_FAILURE' }]; | ||
store.dispatch(fetchArticlesThunk()).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
|
||
it('should hanlde fetchArticlesSuccess', () => { | ||
const mockData = { | ||
results: [ | ||
{ | ||
title: '', | ||
body: '', | ||
}, | ||
], | ||
}; | ||
moxios.stubRequest( | ||
`${APP_URL}/articles`, | ||
{ | ||
status: 200, | ||
response: mockData, | ||
}, | ||
); | ||
store.clearActions(); | ||
const expectedActions = [ | ||
{ articles: [{ body: '', title: '' }], type: 'FETCH_ARTICLES_SUCCESS' }, | ||
]; | ||
store.dispatch(fetchArticlesThunk()).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('fetchArticleSucess', () => { | ||
it('should create an action on successful fetching of all articles', () => { | ||
const article = { | ||
title: 'training a dragon', | ||
body: 'how to train a dragon', | ||
}; | ||
const expectedAction = { | ||
type: ACTION_TYPE.FETCH_ARTICLES_SUCCESS, | ||
articles: article, | ||
}; | ||
expect(fetchArticlesSuccess(article)).toEqual(expectedAction); | ||
}); | ||
}); | ||
|
||
describe('fetchArticlesFailure', () => { | ||
it('should create an action on failure to fetch all articles', () => { | ||
const msg = 'no internet connection'; | ||
|
||
const expectedAction = { | ||
type: ACTION_TYPE.FETCH_ARTICLES_FAILURE, | ||
errorMessage: msg, | ||
}; | ||
expect(fetchArticlesFailure(msg)).toEqual(expectedAction); | ||
}); | ||
}); |
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
Oops, something went wrong.