Bug: Fix conversation not loading from the links in email (#602)

Bug: Load conversation from links
This commit is contained in:
Pranav Raj S
2020-03-08 22:08:25 +05:30
committed by GitHub
parent a8ac048716
commit 2a4fb7b056
14 changed files with 118 additions and 36 deletions

View File

@@ -7,6 +7,15 @@ import FBChannel from '../../../api/channel/fbChannel';
// actions
const actions = {
getConversation: async ({ commit }, conversationId) => {
try {
const response = await ConversationApi.show(conversationId);
commit(types.default.ADD_CONVERSATION, response.data);
} catch (error) {
// Ignore error
}
},
fetchAllConversations: async ({ commit, dispatch }, params) => {
commit(types.default.SET_LIST_LOADING_STATUS);
try {

View File

@@ -33,12 +33,13 @@ const getters = {
getChatListLoadingStatus: ({ listLoadingStatus }) => listLoadingStatus,
getAllMessagesLoaded(_state) {
const [chat] = getSelectedChatConversation(_state);
return chat.allMessagesLoaded === undefined
return !chat || chat.allMessagesLoaded === undefined
? false
: chat.allMessagesLoaded;
},
getUnreadCount(_state) {
const [chat] = getSelectedChatConversation(_state);
if (!chat) return [];
return chat.messages.filter(
chatMessage =>
chatMessage.created_at * 1000 > chat.agent_last_seen_at * 1000 &&

View File

@@ -0,0 +1,24 @@
import axios from 'axios';
import actions from '../../conversations/actions';
import * as types from '../../../mutation-types';
const commit = jest.fn();
global.axios = axios;
jest.mock('axios');
describe('#actions', () => {
describe('#getConversation', () => {
it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue({ data: { id: 1, meta: {} } });
await actions.getConversation({ commit }, 1);
expect(commit.mock.calls).toEqual([
[types.default.ADD_CONVERSATION, { id: 1, meta: {} }],
]);
});
it('sends correct actions if API is error', async () => {
axios.get.mockRejectedValue({ message: 'Incorrect header' });
await actions.getConversation({ commit });
expect(commit.mock.calls).toEqual([]);
});
});
});