2021-05-10 07:31:00 +00:00
|
|
|
import { API } from 'widget/helpers/axios';
|
|
|
|
import { actions } from '../../campaign';
|
|
|
|
import { campaigns } from './data';
|
|
|
|
|
|
|
|
const commit = jest.fn();
|
|
|
|
jest.mock('widget/helpers/axios');
|
|
|
|
|
|
|
|
describe('#actions', () => {
|
|
|
|
describe('#fetchCampaigns', () => {
|
|
|
|
it('sends correct actions if API is success', async () => {
|
|
|
|
API.get.mockResolvedValue({ data: campaigns });
|
2021-05-17 16:08:35 +00:00
|
|
|
await actions.fetchCampaigns(
|
|
|
|
{ commit },
|
|
|
|
{ websiteToken: 'XDsafmADasd', currentURL: 'https://www.chatwoot.com' }
|
|
|
|
);
|
|
|
|
expect(commit.mock.calls).not.toEqual([
|
2021-05-10 07:31:00 +00:00
|
|
|
['setCampaigns', campaigns],
|
|
|
|
['setError', false],
|
|
|
|
['setHasFetched', true],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
it('sends correct actions if API is error', async () => {
|
|
|
|
API.get.mockRejectedValue({ message: 'Authentication required' });
|
2021-05-17 16:08:35 +00:00
|
|
|
await actions.fetchCampaigns(
|
|
|
|
{ commit },
|
|
|
|
{ websiteToken: 'XDsafmADasd', currentURL: 'https://www.chatwoot.com' }
|
|
|
|
);
|
2021-05-10 07:31:00 +00:00
|
|
|
expect(commit.mock.calls).toEqual([
|
|
|
|
['setError', true],
|
|
|
|
['setHasFetched', true],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|