-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
164047041 Feature (Report Article): Users should be able to report an…
… article - Users should report an article as long as they are not the authors - A user cannot report an article twice. - Write tests [Finishes #164047041]
- Loading branch information
1 parent
23f83db
commit a8da5d9
Showing
11 changed files
with
432 additions
and
138 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import axios from 'axios'; | ||
import { REPORT_ARTICLE, ACTION_FAILED } from './types'; | ||
import axiosHeader from '../axios_config'; | ||
|
||
const apiURL2 = 'https://aholympian.herokuapp.com/api/'; | ||
|
||
export const reportArticle = (slug, postData) => async (dispatch) => { | ||
await axios | ||
.post(`${apiURL2}report/${slug}/`, postData, axiosHeader) | ||
.then((result) => { | ||
dispatch({ | ||
type: REPORT_ARTICLE, | ||
payload: result.data, | ||
}); | ||
}) | ||
.catch((error) => { | ||
console.log(JSON.stringify(error)); | ||
dispatch({ | ||
type: ACTION_FAILED, | ||
payload: error.response.data, | ||
}); | ||
}); | ||
}; |
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,56 @@ | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import mockAxios from 'axios'; | ||
|
||
import { REPORT_ARTICLE, ACTION_FAILED } from '../types'; | ||
import { reportArticle } from '../reportArticle'; | ||
|
||
|
||
describe('testing report article', () => { | ||
it('tests reporting an article', () => { | ||
const testStore = configureMockStore([thunk]); | ||
const store = testStore({}); | ||
mockAxios.post.mockResolvedValue({ | ||
data: {}, | ||
}); | ||
|
||
const expectedAction = [ | ||
{ | ||
type: REPORT_ARTICLE, | ||
payload: {}, | ||
}, | ||
]; | ||
|
||
return store.dispatch(reportArticle({})).then(() => { | ||
expect(store.getActions()).toEqual(expectedAction); | ||
}); | ||
}); | ||
it("dispatches REPORT_ARTICLE action and returns an error", async () => { | ||
const testStore = configureMockStore([thunk]); | ||
const store = testStore({}); | ||
mockAxios.post.mockImplementationOnce(() => | ||
Promise.reject({ | ||
error: "Something bad happened" | ||
}) | ||
); | ||
|
||
try { | ||
await store.dispatch(reportArticle()); | ||
} catch { | ||
const actions = store.getActions(); | ||
|
||
expect.assertions(1); | ||
|
||
const expectedAction = [ | ||
{ | ||
type: REPORT_ARTICLE, | ||
payload: {}, | ||
}, | ||
]; | ||
|
||
return store.dispatch(reportArticle({})).then(() => { | ||
expect(store.getActions()).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
Oops, something went wrong.