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
2 changed files with 49 additions and 61 deletions

View File

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

View File

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