feat: Articles store integration (#5133)
This commit is contained in:
@@ -15,10 +15,22 @@ jest.mock('axios');
|
||||
describe('#actions', () => {
|
||||
describe('#index', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.get.mockResolvedValue({ data: articleList });
|
||||
await actions.index({ commit });
|
||||
axios.get.mockResolvedValue({
|
||||
data: {
|
||||
payload: articleList,
|
||||
meta: {
|
||||
current_page: '1',
|
||||
articles_count: 5,
|
||||
},
|
||||
},
|
||||
});
|
||||
await actions.index(
|
||||
{ commit },
|
||||
{ pageNumber: 1, portalSlug: 'test', locale: 'en' }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_UI_FLAG, { isFetching: true }],
|
||||
[types.default.CLEAR_ARTICLES],
|
||||
[
|
||||
types.default.ADD_MANY_ARTICLES,
|
||||
[
|
||||
@@ -29,13 +41,22 @@ describe('#actions', () => {
|
||||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
types.default.SET_ARTICLES_META,
|
||||
{ current_page: '1', articles_count: 5 },
|
||||
],
|
||||
[types.default.ADD_MANY_ARTICLES_ID, [1]],
|
||||
[types.default.SET_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(actions.index({ commit })).rejects.toThrow(Error);
|
||||
await expect(
|
||||
actions.index(
|
||||
{ commit },
|
||||
{ pageNumber: 1, portalSlug: 'test', locale: 'en' }
|
||||
)
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_UI_FLAG, { isFetching: true }],
|
||||
[types.default.SET_UI_FLAG, { isFetching: false }],
|
||||
|
||||
Reference in New Issue
Block a user