2020-05-09 16:32:43 +00:00
|
|
|
import { actions } from '../../conversationAttributes';
|
|
|
|
import { API } from 'widget/helpers/axios';
|
|
|
|
|
|
|
|
const commit = jest.fn();
|
|
|
|
jest.mock('widget/helpers/axios');
|
|
|
|
|
|
|
|
describe('#actions', () => {
|
2021-06-30 15:39:44 +00:00
|
|
|
describe('#get attributes', () => {
|
2020-05-09 16:32:43 +00:00
|
|
|
it('sends mutation if api is success', async () => {
|
|
|
|
API.get.mockResolvedValue({ data: { id: 1, status: 'bot' } });
|
2021-06-30 15:39:44 +00:00
|
|
|
await actions.getAttributes({ commit });
|
2020-05-09 16:32:43 +00:00
|
|
|
expect(commit.mock.calls).toEqual([
|
|
|
|
['SET_CONVERSATION_ATTRIBUTES', { id: 1, status: 'bot' }],
|
2020-07-07 18:34:44 +00:00
|
|
|
['conversation/setMetaUserLastSeenAt', undefined, { root: true }],
|
2020-05-09 16:32:43 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
it('doesnot send mutation if api is error', async () => {
|
|
|
|
API.get.mockRejectedValue({ message: 'Invalid Headers' });
|
2021-06-30 15:39:44 +00:00
|
|
|
await actions.getAttributes({ commit });
|
2020-05-09 16:32:43 +00:00
|
|
|
expect(commit.mock.calls).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-30 15:39:44 +00:00
|
|
|
describe('#update attributes', () => {
|
2020-05-09 16:32:43 +00:00
|
|
|
it('sends correct mutations', () => {
|
|
|
|
actions.update({ commit }, { id: 1, status: 'bot' });
|
|
|
|
expect(commit).toBeCalledWith('UPDATE_CONVERSATION_ATTRIBUTES', {
|
|
|
|
id: 1,
|
|
|
|
status: 'bot',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-06-30 15:39:44 +00:00
|
|
|
describe('#clear attributes', () => {
|
|
|
|
it('sends correct mutations', () => {
|
|
|
|
actions.clearConversationAttributes({ commit });
|
|
|
|
expect(commit).toBeCalledWith('CLEAR_CONVERSATION_ATTRIBUTES');
|
|
|
|
});
|
|
|
|
});
|
2020-05-09 16:32:43 +00:00
|
|
|
});
|