2020-03-08 16:38:25 +00:00
|
|
|
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 () => {
|
2020-06-02 17:29:02 +00:00
|
|
|
axios.get.mockResolvedValue({
|
|
|
|
data: { id: 1, meta: { sender: { id: 1, name: 'Contact 1' } } },
|
|
|
|
});
|
2020-03-08 16:38:25 +00:00
|
|
|
await actions.getConversation({ commit }, 1);
|
|
|
|
expect(commit.mock.calls).toEqual([
|
2020-06-02 17:29:02 +00:00
|
|
|
[
|
2020-06-25 15:34:03 +00:00
|
|
|
types.default.UPDATE_CONVERSATION,
|
2020-06-02 17:29:02 +00:00
|
|
|
{ id: 1, meta: { sender: { id: 1, name: 'Contact 1' } } },
|
|
|
|
],
|
|
|
|
['contacts/SET_CONTACT_ITEM', { id: 1, name: 'Contact 1' }],
|
2020-03-08 16:38:25 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
it('sends correct actions if API is error', async () => {
|
|
|
|
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
|
|
|
await actions.getConversation({ commit });
|
|
|
|
expect(commit.mock.calls).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
2020-05-26 12:13:59 +00:00
|
|
|
describe('#muteConversation', () => {
|
|
|
|
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]]);
|
|
|
|
});
|
|
|
|
it('sends correct actions if API is error', async () => {
|
|
|
|
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
|
|
|
await actions.getConversation({ commit });
|
|
|
|
expect(commit.mock.calls).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
2020-03-08 16:38:25 +00:00
|
|
|
});
|