mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
Due to the pattern `**/specs/*.spec.js` defined in CircleCI, none of the frontend spec in the folders such as `specs/<domain-name>/getters.spec.js` were not executed in Circle CI. This PR fixes the issue, along with the following changes: - Use vitest instead of jest - Remove jest dependancies - Update tests to work with vitest --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
84 lines
2.8 KiB
JavaScript
84 lines
2.8 KiB
JavaScript
import axios from 'axios';
|
|
import { actions, getters } from '../../accounts';
|
|
import * as types from '../../../mutation-types';
|
|
|
|
const accountData = {
|
|
id: 1,
|
|
name: 'Company one',
|
|
locale: 'en',
|
|
};
|
|
|
|
const newAccountInfo = {
|
|
accountName: 'Company two',
|
|
};
|
|
|
|
const commit = vi.fn();
|
|
global.axios = axios;
|
|
vi.mock('axios');
|
|
|
|
describe('#actions', () => {
|
|
describe('#get', () => {
|
|
it('sends correct actions if API is success', async () => {
|
|
axios.get.mockResolvedValue({ data: accountData });
|
|
await actions.get({ commit });
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isFetchingItem: true }],
|
|
[types.default.ADD_ACCOUNT, accountData],
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isFetchingItem: false }],
|
|
]);
|
|
});
|
|
it('sends correct actions if API is error', async () => {
|
|
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
|
await actions.get({ commit });
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isFetchingItem: true }],
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isFetchingItem: false }],
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('#update', () => {
|
|
it('sends correct actions if API is success', async () => {
|
|
axios.patch.mockResolvedValue();
|
|
await actions.update({ commit, getters }, accountData);
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: true }],
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: false }],
|
|
]);
|
|
});
|
|
it('sends correct actions if API is error', async () => {
|
|
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
|
await expect(
|
|
actions.update({ commit, getters }, accountData)
|
|
).rejects.toThrow(Error);
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: true }],
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: false }],
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('#create', () => {
|
|
it('sends correct actions if API is success', async () => {
|
|
axios.post.mockResolvedValue({
|
|
data: { data: { id: 1, name: 'John' } },
|
|
});
|
|
await actions.create({ commit, getters }, newAccountInfo);
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isCreating: true }],
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isCreating: false }],
|
|
]);
|
|
});
|
|
it('sends correct actions if API is error', async () => {
|
|
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
|
await expect(
|
|
actions.create({ commit, getters }, newAccountInfo)
|
|
).rejects.toThrow(Error);
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isCreating: true }],
|
|
[types.default.SET_ACCOUNT_UI_FLAG, { isCreating: false }],
|
|
]);
|
|
});
|
|
});
|
|
});
|