2020-06-09 10:56:33 +00:00
|
|
|
import axios from 'axios';
|
2020-06-14 08:37:52 +00:00
|
|
|
import { actions } from '../../conversationStats';
|
2020-06-09 10:56:33 +00:00
|
|
|
import * as types from '../../../mutation-types';
|
|
|
|
|
|
|
|
const commit = jest.fn();
|
|
|
|
global.axios = axios;
|
|
|
|
jest.mock('axios');
|
|
|
|
|
|
|
|
describe('#actions', () => {
|
2020-06-14 08:37:52 +00:00
|
|
|
describe('#get', () => {
|
|
|
|
it('sends correct mutations if API is success', async () => {
|
2020-06-09 10:56:33 +00:00
|
|
|
axios.get.mockResolvedValue({ data: { meta: { mine_count: 1 } } });
|
2020-06-14 08:37:52 +00:00
|
|
|
await actions.get(
|
2020-06-09 10:56:33 +00:00
|
|
|
{ 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' });
|
2020-06-14 08:37:52 +00:00
|
|
|
await actions.get(
|
2020-06-09 10:56:33 +00:00
|
|
|
{ commit },
|
|
|
|
{ inboxId: 1, assigneeTpe: 'me', status: 'open' }
|
|
|
|
);
|
|
|
|
expect(commit.mock.calls).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
2020-06-14 08:37:52 +00:00
|
|
|
|
|
|
|
describe('#set', () => {
|
|
|
|
it('sends correct mutations', async () => {
|
|
|
|
actions.set(
|
|
|
|
{ commit },
|
|
|
|
{ mine_count: 1, unassigned_count: 1, all_count: 2 }
|
|
|
|
);
|
|
|
|
expect(commit.mock.calls).toEqual([
|
|
|
|
[
|
|
|
|
types.default.SET_CONV_TAB_META,
|
|
|
|
{ mine_count: 1, unassigned_count: 1, all_count: 2 },
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2020-06-09 10:56:33 +00:00
|
|
|
});
|