fix: Remove * as import from conversation module (#3366)

* fix: Remove * as import from conversation module

* Remove * as import from conversation test spec

Co-authored-by: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com>
This commit is contained in:
Pranav Raj S 2021-11-12 13:41:43 +05:30 committed by GitHub
parent 564fa5f392
commit b119d9e729
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 61 deletions

View file

@ -1,5 +1,5 @@
import Vue from 'vue';
import * as types from '../../mutation-types';
import types from '../../mutation-types';
import ConversationApi from '../../../api/inbox/conversation';
import MessageApi from '../../../api/inbox/message';
import { MESSAGE_STATUS, MESSAGE_TYPE } from 'shared/constants/messages';
@ -10,29 +10,26 @@ const actions = {
getConversation: async ({ commit }, conversationId) => {
try {
const response = await ConversationApi.show(conversationId);
commit(types.default.UPDATE_CONVERSATION, response.data);
commit(
`contacts/${types.default.SET_CONTACT_ITEM}`,
response.data.meta.sender
);
commit(types.UPDATE_CONVERSATION, response.data);
commit(`contacts/${types.SET_CONTACT_ITEM}`, response.data.meta.sender);
} catch (error) {
// Ignore error
}
},
fetchAllConversations: async ({ commit, dispatch }, params) => {
commit(types.default.SET_LIST_LOADING_STATUS);
commit(types.SET_LIST_LOADING_STATUS);
try {
const response = await ConversationApi.get(params);
const {
data: { payload: chatList, meta: metaData },
} = response.data;
commit(types.default.SET_ALL_CONVERSATION, chatList);
commit(types.SET_ALL_CONVERSATION, chatList);
dispatch('conversationStats/set', metaData);
dispatch('conversationLabels/setBulkConversationLabels', chatList);
commit(types.default.CLEAR_LIST_LOADING_STATUS);
commit(types.CLEAR_LIST_LOADING_STATUS);
commit(
`contacts/${types.default.SET_CONTACTS}`,
`contacts/${types.SET_CONTACTS}`,
chatList.map(chat => chat.meta.sender)
);
dispatch(
@ -53,11 +50,11 @@ const actions = {
},
emptyAllConversations({ commit }) {
commit(types.default.EMPTY_ALL_CONVERSATION);
commit(types.EMPTY_ALL_CONVERSATION);
},
clearSelectedState({ commit }) {
commit(types.default.CLEAR_CURRENT_CHAT_WINDOW);
commit(types.CLEAR_CURRENT_CHAT_WINDOW);
},
fetchPreviousMessages: async ({ commit }, data) => {
@ -65,16 +62,16 @@ const actions = {
const {
data: { meta, payload },
} = await MessageApi.getPreviousMessages(data);
commit(
`conversationMetadata/${types.default.SET_CONVERSATION_METADATA}`,
{ id: data.conversationId, data: meta }
);
commit(types.default.SET_PREVIOUS_CONVERSATIONS, {
commit(`conversationMetadata/${types.SET_CONVERSATION_METADATA}`, {
id: data.conversationId,
data: meta,
});
commit(types.SET_PREVIOUS_CONVERSATIONS, {
id: data.conversationId,
data: payload,
});
if (payload.length < 20) {
commit(types.default.SET_ALL_MESSAGES_LOADED);
commit(types.SET_ALL_MESSAGES_LOADED);
}
} catch (error) {
// Handle error
@ -82,8 +79,8 @@ const actions = {
},
async setActiveChat({ commit, dispatch }, data) {
commit(types.default.SET_CURRENT_CHAT_WINDOW, data);
commit(types.default.CLEAR_ALL_MESSAGES_LOADED);
commit(types.SET_CURRENT_CHAT_WINDOW, data);
commit(types.CLEAR_ALL_MESSAGES_LOADED);
if (data.dataFetched === undefined) {
try {
@ -111,7 +108,7 @@ const actions = {
},
setCurrentChatAssignee({ commit }, assignee) {
commit(types.default.ASSIGN_AGENT, assignee);
commit(types.ASSIGN_AGENT, assignee);
},
assignTeam: async ({ dispatch }, { conversationId, teamId }) => {
@ -127,7 +124,7 @@ const actions = {
},
setCurrentChatTeam({ commit }, team) {
commit(types.default.ASSIGN_TEAM, team);
commit(types.ASSIGN_TEAM, team);
},
toggleStatus: async (
@ -147,7 +144,7 @@ const actions = {
status,
snoozedUntil,
});
commit(types.default.CHANGE_CONVERSATION_STATUS, {
commit(types.CHANGE_CONVERSATION_STATUS, {
conversationId,
status: updatedStatus,
snoozedUntil: updatedSnoozedUntil,
@ -161,9 +158,9 @@ const actions = {
// eslint-disable-next-line no-useless-catch
try {
const pendingMessage = createPendingMessage(data);
commit(types.default.ADD_MESSAGE, pendingMessage);
commit(types.ADD_MESSAGE, pendingMessage);
const response = await MessageApi.create(pendingMessage);
commit(types.default.ADD_MESSAGE, {
commit(types.ADD_MESSAGE, {
...response.data,
status: MESSAGE_STATUS.SENT,
});
@ -173,9 +170,9 @@ const actions = {
},
addMessage({ commit }, message) {
commit(types.default.ADD_MESSAGE, message);
commit(types.ADD_MESSAGE, message);
if (message.message_type === MESSAGE_TYPE.INCOMING) {
commit(types.default.SET_CONVERSATION_CAN_REPLY, {
commit(types.SET_CONVERSATION_CAN_REPLY, {
conversationId: message.conversation_id,
canReply: true,
});
@ -183,7 +180,7 @@ const actions = {
},
updateMessage({ commit }, message) {
commit(types.default.ADD_MESSAGE, message);
commit(types.ADD_MESSAGE, message);
},
deleteMessage: async function deleteLabels(
@ -194,7 +191,7 @@ const actions = {
const response = await MessageApi.delete(conversationId, messageId);
const { data } = response;
// The delete message is actually deleting the content.
commit(types.default.ADD_MESSAGE, data);
commit(types.ADD_MESSAGE, data);
} catch (error) {
throw new Error(error);
}
@ -207,7 +204,7 @@ const actions = {
meta: { sender },
} = conversation;
if (!currentInbox || Number(currentInbox) === inboxId) {
commit(types.default.ADD_CONVERSATION, conversation);
commit(types.ADD_CONVERSATION, conversation);
dispatch('contacts/setContact', sender);
}
},
@ -216,7 +213,7 @@ const actions = {
const {
meta: { sender },
} = conversation;
commit(types.default.UPDATE_CONVERSATION, conversation);
commit(types.UPDATE_CONVERSATION, conversation);
dispatch('contacts/setContact', sender);
},
@ -225,38 +222,35 @@ const actions = {
const {
data: { id, agent_last_seen_at: lastSeen },
} = await ConversationApi.markMessageRead(data);
setTimeout(
() => commit(types.default.MARK_MESSAGE_READ, { id, lastSeen }),
4000
);
setTimeout(() => commit(types.MARK_MESSAGE_READ, { id, lastSeen }), 4000);
} catch (error) {
// Handle error
}
},
setChatFilter({ commit }, data) {
commit(types.default.CHANGE_CHAT_STATUS_FILTER, data);
commit(types.CHANGE_CHAT_STATUS_FILTER, data);
},
updateAssignee({ commit }, data) {
commit(types.default.UPDATE_ASSIGNEE, data);
commit(types.UPDATE_ASSIGNEE, data);
},
updateConversationContact({ commit }, data) {
if (data.id) {
commit(`contacts/${types.default.SET_CONTACT_ITEM}`, data);
commit(`contacts/${types.SET_CONTACT_ITEM}`, data);
}
commit(types.default.UPDATE_CONVERSATION_CONTACT, data);
commit(types.UPDATE_CONVERSATION_CONTACT, data);
},
setActiveInbox({ commit }, inboxId) {
commit(types.default.SET_ACTIVE_INBOX, inboxId);
commit(types.SET_ACTIVE_INBOX, inboxId);
},
muteConversation: async ({ commit }, conversationId) => {
try {
await ConversationApi.mute(conversationId);
commit(types.default.MUTE_CONVERSATION);
commit(types.MUTE_CONVERSATION);
} catch (error) {
//
}
@ -265,7 +259,7 @@ const actions = {
unmuteConversation: async ({ commit }, conversationId) => {
try {
await ConversationApi.unmute(conversationId);
commit(types.default.UNMUTE_CONVERSATION);
commit(types.UNMUTE_CONVERSATION);
} catch (error) {
//
}
@ -289,10 +283,7 @@ const actions = {
customAttributes,
});
const { custom_attributes } = response.data;
commit(
types.default.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES,
custom_attributes
);
commit(types.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES, custom_attributes);
} catch (error) {
// Handle error
}

View file

@ -1,6 +1,6 @@
import axios from 'axios';
import actions from '../../conversations/actions';
import * as types from '../../../mutation-types';
import types from '../../../mutation-types';
const commit = jest.fn();
const dispatch = jest.fn();
@ -16,7 +16,7 @@ describe('#actions', () => {
await actions.getConversation({ commit }, 1);
expect(commit.mock.calls).toEqual([
[
types.default.UPDATE_CONVERSATION,
types.UPDATE_CONVERSATION,
{ id: 1, meta: { sender: { id: 1, name: 'Contact 1' } } },
],
['contacts/SET_CONTACT_ITEM', { id: 1, name: 'Contact 1' }],
@ -32,7 +32,7 @@ describe('#actions', () => {
it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue(null);
await actions.muteConversation({ commit }, 1);
expect(commit.mock.calls).toEqual([[types.default.MUTE_CONVERSATION]]);
expect(commit.mock.calls).toEqual([[types.MUTE_CONVERSATION]]);
});
it('sends correct actions if API is error', async () => {
axios.get.mockRejectedValue({ message: 'Incorrect header' });
@ -50,7 +50,7 @@ describe('#actions', () => {
};
actions.updateConversation({ commit, dispatch }, conversation);
expect(commit.mock.calls).toEqual([
[types.default.UPDATE_CONVERSATION, conversation],
[types.UPDATE_CONVERSATION, conversation],
]);
expect(dispatch.mock.calls).toEqual([
[
@ -92,7 +92,7 @@ describe('#actions', () => {
conversation
);
expect(commit.mock.calls).toEqual([
[types.default.ADD_CONVERSATION, conversation],
[types.ADD_CONVERSATION, conversation],
]);
expect(dispatch.mock.calls).toEqual([
[
@ -114,7 +114,7 @@ describe('#actions', () => {
};
actions.addConversation({ commit, dispatch, state: {} }, conversation);
expect(commit.mock.calls).toEqual([
[types.default.ADD_CONVERSATION, conversation],
[types.ADD_CONVERSATION, conversation],
]);
expect(dispatch.mock.calls).toEqual([
[
@ -136,9 +136,9 @@ describe('#actions', () => {
};
actions.addMessage({ commit }, message);
expect(commit.mock.calls).toEqual([
[types.default.ADD_MESSAGE, message],
[types.ADD_MESSAGE, message],
[
types.default.SET_CONVERSATION_CAN_REPLY,
types.SET_CONVERSATION_CAN_REPLY,
{ conversationId: 1, canReply: true },
],
]);
@ -150,7 +150,7 @@ describe('#actions', () => {
conversation_id: 1,
};
actions.addMessage({ commit }, message);
expect(commit.mock.calls).toEqual([[types.default.ADD_MESSAGE, message]]);
expect(commit.mock.calls).toEqual([[types.ADD_MESSAGE, message]]);
});
});
@ -168,7 +168,7 @@ describe('#actions', () => {
jest.runAllTimers();
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls).toEqual([
[types.default.MARK_MESSAGE_READ, { id: 1, lastSeen }],
[types.MARK_MESSAGE_READ, { id: 1, lastSeen }],
]);
});
it('sends correct mutations if api is unsuccessful', async () => {
@ -270,7 +270,7 @@ describe('#deleteMessage', () => {
axios.delete.mockResolvedValue({ data: { id: 1, content: 'deleted' } });
await actions.deleteMessage({ commit }, { conversationId, messageId });
expect(commit.mock.calls).toEqual([
[types.default.ADD_MESSAGE, { id: 1, content: 'deleted' }],
[types.ADD_MESSAGE, { id: 1, content: 'deleted' }],
]);
});
it('sends no actions if API is error', async () => {
@ -295,10 +295,7 @@ describe('#deleteMessage', () => {
}
);
expect(commit.mock.calls).toEqual([
[
types.default.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES,
{ order_d: '1001' },
],
[types.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES, { order_d: '1001' }],
]);
});
});