feat: Add the ability to delete/archive articles (#5319)
This commit is contained in:
@@ -100,7 +100,7 @@ export const actions = {
|
||||
});
|
||||
}
|
||||
},
|
||||
delete: async ({ commit }, articleId) => {
|
||||
delete: async ({ commit }, { portalSlug, articleId }) => {
|
||||
commit(types.UPDATE_ARTICLE_FLAG, {
|
||||
uiFlags: {
|
||||
isDeleting: true,
|
||||
@@ -108,8 +108,7 @@ export const actions = {
|
||||
articleId,
|
||||
});
|
||||
try {
|
||||
await articlesAPI.delete(articleId);
|
||||
|
||||
await articlesAPI.deleteArticle({ portalSlug, articleId });
|
||||
commit(types.REMOVE_ARTICLE, articleId);
|
||||
commit(types.REMOVE_ARTICLE_ID, articleId);
|
||||
return articleId;
|
||||
|
||||
@@ -13,9 +13,11 @@ export const getters = {
|
||||
},
|
||||
allArticles: (...getterArguments) => {
|
||||
const [state, _getters] = getterArguments;
|
||||
const articles = state.articles.allIds.map(id => {
|
||||
return _getters.articleById(id);
|
||||
});
|
||||
const articles = state.articles.allIds
|
||||
.map(id => {
|
||||
return _getters.articleById(id);
|
||||
})
|
||||
.filter(article => article !== undefined);
|
||||
return articles;
|
||||
},
|
||||
getMeta: state => {
|
||||
|
||||
@@ -142,7 +142,11 @@ describe('#actions', () => {
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.delete.mockResolvedValue({ data: articleList[0] });
|
||||
await actions.delete({ commit }, articleList[0].id);
|
||||
await actions.delete(
|
||||
{ commit },
|
||||
{ portalSlug: 'test', articleId: articleList[0].id }
|
||||
);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
types.default.UPDATE_ARTICLE_FLAG,
|
||||
@@ -159,7 +163,10 @@ describe('#actions', () => {
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.delete.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.delete({ commit }, articleList[0].id)
|
||||
actions.delete(
|
||||
{ commit },
|
||||
{ portalSlug: 'test', articleId: articleList[0].id }
|
||||
)
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user