-
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.
feat(view article): allow user view one article (#21)
- Ensures that a user can view a single article. [Delivers #163356764]
- Loading branch information
1 parent
281111e
commit 8ffa669
Showing
14 changed files
with
813 additions
and
16 deletions.
There are no files selected for viewing
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
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,82 @@ | ||
import thunk from 'redux-thunk'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import moxios from 'moxios'; | ||
import * as actions from '../viewArticleActions'; | ||
import {getErr} from "../viewArticleActions"; | ||
|
||
const middleWare = [thunk]; | ||
const mockStore = configureMockStore(middleWare); | ||
|
||
describe('Registration Actions', () => { | ||
describe('register user', () => { | ||
beforeEach(() => { | ||
moxios.install(); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(); | ||
}); | ||
|
||
it('should return GET_ARTICLE action', () => { | ||
const expectedAction = { | ||
type: actions.ARTICLE_GET_DONE, | ||
article: {}, | ||
}; | ||
const action = actions.articleGetDone({}) | ||
expect(action).toEqual(expectedAction); | ||
}); | ||
it('', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: {}, | ||
}); | ||
}); | ||
|
||
const processing = true; | ||
const processed = false; | ||
const slug = "test"; | ||
const success = true; | ||
const article = {}; | ||
const expectedActions = [ | ||
{ type: actions.ARTICLE_GET_PROCESSING, processing }, | ||
{ type: actions.ARTICLE_GET_DONE, article}, | ||
{type:actions.ARTICLE_GET_SUCCESS, success}, | ||
{ type: actions.ARTICLE_GET_PROCESSING, processing:processed }, | ||
]; | ||
const store = mockStore({ user: {}, expectedActions }); | ||
return store.dispatch(actions.fetchArticle(slug)).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}, | ||
); | ||
}); | ||
|
||
it('Returns an error on fail', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 500, | ||
response: {reason: "Some"}, | ||
}); | ||
}); | ||
const error = "Some"; | ||
const processing = true; | ||
const processed = false; | ||
const slug = "test"; | ||
const reason = getErr(error); | ||
const success = false; | ||
const article = {}; | ||
const expectedActions = [ | ||
{ type: actions.ARTICLE_GET_PROCESSING, processing }, | ||
{ type: actions.ARTICLE_GET_ERROR, reason: reason}, | ||
{ type: actions.ARTICLE_GET_PROCESSING, processing:processed }, | ||
{type:actions.ARTICLE_GET_SUCCESS, success}, | ||
]; | ||
const store = mockStore({ user: {}, expectedActions }); | ||
return store.dispatch(actions.fetchArticle(slug)).catch(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
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,42 @@ | ||
import axios from 'axios'; | ||
|
||
export const ARTICLE_GET_PROCESSING = 'ARTICLE_GET_PROCESSING'; | ||
export const articleGetProcessing = processing => ({ | ||
type: ARTICLE_GET_PROCESSING, | ||
processing, | ||
}); | ||
|
||
export const ARTICLE_GET_DONE = 'ARTICLE_GET_DONE'; | ||
export const articleGetDone = article => ({ | ||
type: ARTICLE_GET_DONE, | ||
article, | ||
}); | ||
|
||
export const ARTICLE_GET_ERROR = 'ARTICLE_GET_ERROR'; | ||
export const articleGetError = reason => ({ | ||
type: ARTICLE_GET_ERROR, | ||
reason, | ||
}); | ||
|
||
export const ARTICLE_GET_SUCCESS = 'ARTICLE_GET_SUCCESS'; | ||
export const articleGetSuccess = success => ({ | ||
type: ARTICLE_GET_SUCCESS, | ||
success, | ||
}); | ||
|
||
export const getErr = error => (error || 'Something went wrong'); | ||
|
||
export const fetchArticle = slug => (dispatch) => { | ||
dispatch(articleGetProcessing(true)); | ||
return axios.get( | ||
`https://ah-technocrats.herokuapp.com/api/articles/${slug}`, | ||
).then((response) => { | ||
dispatch(articleGetDone(response.data)); | ||
dispatch(articleGetSuccess(true)); | ||
dispatch(articleGetProcessing(false)); | ||
}).catch((error) => { | ||
dispatch(articleGetError(getErr(error))); | ||
dispatch(articleGetProcessing(false)); | ||
dispatch(articleGetSuccess(false)); | ||
}); | ||
}; |
Oops, something went wrong.