feat: Create modal to merge two contacts (#2457)
This commit is contained in:
committed by
GitHub
parent
6c3e2a0bd3
commit
b33701a666
@@ -4,6 +4,7 @@ import {
|
||||
} from 'shared/helpers/CustomErrors';
|
||||
import types from '../../mutation-types';
|
||||
import ContactAPI from '../../../api/contacts';
|
||||
import AccountActionsAPI from '../../../api/accountActions';
|
||||
|
||||
export const actions = {
|
||||
search: async ({ commit }, { search, page, sortAttr, label }) => {
|
||||
@@ -137,6 +138,18 @@ export const actions = {
|
||||
commit(types.SET_CONTACT_ITEM, data);
|
||||
},
|
||||
|
||||
merge: async ({ commit }, { childId, parentId }) => {
|
||||
commit(types.SET_CONTACT_UI_FLAG, { isMerging: true });
|
||||
try {
|
||||
const response = await AccountActionsAPI.merge(parentId, childId);
|
||||
commit(types.SET_CONTACT_ITEM, response.data);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
} finally {
|
||||
commit(types.SET_CONTACT_UI_FLAG, { isMerging: false });
|
||||
}
|
||||
},
|
||||
|
||||
deleteContactThroughConversations: ({ commit }, id) => {
|
||||
commit(types.DELETE_CONTACT, id);
|
||||
commit(types.CLEAR_CONTACT_CONVERSATIONS, id, { root: true });
|
||||
|
||||
@@ -13,6 +13,7 @@ const state = {
|
||||
isFetchingItem: false,
|
||||
isFetchingInboxes: false,
|
||||
isUpdating: false,
|
||||
isMerging: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
sortOrder: [],
|
||||
|
||||
@@ -168,6 +168,30 @@ describe('#actions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#merge', () => {
|
||||
it('sends correct mutations if API is success', async () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: contactList[0],
|
||||
});
|
||||
await actions.merge({ commit }, { childId: 0, parentId: 1 });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_CONTACT_UI_FLAG, { isMerging: true }],
|
||||
[types.SET_CONTACT_ITEM, contactList[0]],
|
||||
[types.SET_CONTACT_UI_FLAG, { isMerging: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.merge({ commit }, { childId: 0, parentId: 1 })
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_CONTACT_UI_FLAG, { isMerging: true }],
|
||||
[types.SET_CONTACT_UI_FLAG, { isMerging: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deleteContactThroughConversations', () => {
|
||||
it('returns correct mutations', () => {
|
||||
actions.deleteContactThroughConversations({ commit }, contactList[0].id);
|
||||
|
||||
Reference in New Issue
Block a user