-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement actions for liking and disliking an article
Edit toast error to display error message from server
- Loading branch information
ibrahimalausa
committed
Mar 4, 2019
1 parent
27fee6d
commit 8913772
Showing
9 changed files
with
125 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
const actionTypes = { | ||
TOTAL_REACTIONS_LOADING: 'TOTAL_REACTIONS_LOADING', | ||
TOTAL_REACTIONS_SUCCESS: 'TOTAL_REACTIONS_SUCCESS', | ||
TOTAL_REACTIONS_FAILURE: 'TOTAL_REACTIONS_FAILURE' | ||
TOTAL_REACTIONS_FAILURE: 'TOTAL_REACTIONS_FAILURE', | ||
ARTICLE_REACTION_SUCCESS: 'ARTICLE_REACTION_SUCCESS' | ||
}; | ||
|
||
export default actionTypes; |
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
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
23 changes: 23 additions & 0 deletions
23
src/helpers/axiosHelper/test/updateArticleReaction.test.js
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 verify from '../updateArticleReaction'; | ||
import { articleId } from '../../../mockData/readArticle'; | ||
|
||
const result = { | ||
success: true, | ||
message: 'Operation Successful' | ||
}; | ||
|
||
const reactionType = 'dislike'; | ||
|
||
describe('Test for create article reaction function', () => { | ||
it('should return a response object', async () => { | ||
const axiosPut = axios.put; | ||
const urlPath = `${ | ||
process.env.API_BASE_URL | ||
}/articles/reaction/${articleId}/?reaction=${reactionType}`; | ||
axios.put = jest.fn(() => Promise.resolve(result)); | ||
const response = await verify.updateArticleReaction(urlPath); | ||
expect(response).toEqual(result); | ||
axios.put = axiosPut; | ||
}); | ||
}); |
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,12 @@ | ||
import axios from 'axios'; | ||
import { config } from '../jwt'; | ||
|
||
const updateArticleReaction = (articleId, reactionType) => { | ||
const url = `${ | ||
process.env.API_BASE_URL | ||
}/articles/reaction/${articleId}/?reaction=${reactionType}`; | ||
const response = axios.put(url, { articleId, reactionType }, config); | ||
return response; | ||
}; | ||
|
||
export default { updateArticleReaction }; |
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,12 @@ | ||
const error = { | ||
response: { | ||
data: { success: false, message: 'Value must be a UUID' } | ||
} | ||
}; | ||
const reactionType = 'dislike'; | ||
|
||
const validReaction = { | ||
success: true, | ||
message: 'Operation Successful' | ||
}; | ||
export { error, reactionType, validReaction }; |