Bugfix: Update conversation counters in realtime (#944)

* Bug: Update conversation counters in realtime
This commit is contained in:
Pranav Raj S
2020-06-09 16:26:33 +05:30
committed by GitHub
parent 602132119b
commit 40481f6462
11 changed files with 99 additions and 14 deletions

View File

@@ -236,6 +236,15 @@ const actions = {
//
}
},
getConversationStats: async ({ commit }, params) => {
try {
const response = await ConversationApi.meta(params);
commit(types.default.SET_CONV_TAB_META, response.data.meta);
} catch (error) {
// Ignore error
}
},
};
export default actions;

View File

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