Chatwoot/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js
Pranav Raj S f78df91dd2
Chore: Contact Sidebar, conversation cleanup (#908)
- Update sidebar design
- Move every contact data to contacts module
- Revert go to next conversation feature
- Fix issues with new conversation in action cable
- Escape HTML content
- Broadcast event when conversation.contact changes.

Co-authored-by: Sojan <sojan@pepalo.com>
2020-06-02 22:59:02 +05:30

42 lines
1.5 KiB
JavaScript

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: { sender: { id: 1, name: 'Contact 1' } } },
});
await actions.getConversation({ commit }, 1);
expect(commit.mock.calls).toEqual([
[
types.default.ADD_CONVERSATION,
{ id: 1, meta: { sender: { id: 1, name: 'Contact 1' } } },
],
['contacts/SET_CONTACT_ITEM', { id: 1, name: 'Contact 1' }],
]);
});
it('sends correct actions if API is error', async () => {
axios.get.mockRejectedValue({ message: 'Incorrect header' });
await actions.getConversation({ commit });
expect(commit.mock.calls).toEqual([]);
});
});
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([]);
});
});
});