feat: Adds the ability to delete a segment (#3836)

* feat: Adds the ability to delete a segment

* Minor fixes

* Small changes
This commit is contained in:
Sivin Varghese
2022-01-24 17:37:43 +05:30
committed by GitHub
parent e90d064648
commit b304f5a826
8 changed files with 77 additions and 18 deletions

View File

@@ -49,10 +49,10 @@ export const actions = {
commit(types.SET_CUSTOM_VIEW_UI_FLAG, { isCreating: false });
}
},
delete: async ({ commit }, id) => {
delete: async ({ commit }, { id, filterType }) => {
commit(types.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true });
try {
await CustomViewsAPI.delete(id);
await CustomViewsAPI.deleteCustomViews(id, filterType);
commit(types.DELETE_CUSTOM_VIEW, id);
} catch (error) {
throw new Error(error);

View File

@@ -51,18 +51,16 @@ describe('#actions', () => {
describe('#delete', () => {
it('sends correct actions if API is success', async () => {
axios.delete.mockResolvedValue({ data: customViewList[0] });
await actions.delete({ commit }, customViewList[0].id);
await actions.delete({ commit }, { id: 1, filterType: 'contact' });
expect(commit.mock.calls).toEqual([
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true }],
[types.default.DELETE_CUSTOM_VIEW, customViewList[0].id],
[types.default.DELETE_CUSTOM_VIEW, 1],
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: false }],
]);
});
it('sends correct actions if API is error', async () => {
axios.delete.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.delete({ commit }, customViewList[0].id)
).rejects.toThrow(Error);
await expect(actions.delete({ commit }, 1)).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: true }],
[types.default.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: false }],