mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-06 05:57:49 +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>
70 lines
2.4 KiB
JavaScript
70 lines
2.4 KiB
JavaScript
import axios from 'axios';
|
|
import { actions } from '../../userNotificationSettings';
|
|
import * as types from '../../../mutation-types';
|
|
|
|
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: { selected_email_flags: ['conversation_creation'] },
|
|
});
|
|
await actions.get({ commit });
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_USER_NOTIFICATION_UI_FLAG, { isFetching: true }],
|
|
[
|
|
types.default.SET_USER_NOTIFICATION,
|
|
{ selected_email_flags: ['conversation_creation'] },
|
|
],
|
|
[types.default.SET_USER_NOTIFICATION_UI_FLAG, { isFetching: 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_USER_NOTIFICATION_UI_FLAG, { isFetching: true }],
|
|
[types.default.SET_USER_NOTIFICATION_UI_FLAG, { isFetching: false }],
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('#update', () => {
|
|
it('sends correct actions if API is success', async () => {
|
|
axios.patch.mockResolvedValue({
|
|
data: { selected_email_flags: ['conversation_creation'] },
|
|
});
|
|
await actions.update(
|
|
{ commit },
|
|
{ selected_email_flags: ['conversation_creation'] }
|
|
);
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_USER_NOTIFICATION_UI_FLAG, { isUpdating: true }],
|
|
[
|
|
types.default.SET_USER_NOTIFICATION,
|
|
{ selected_email_flags: ['conversation_creation'] },
|
|
],
|
|
[types.default.SET_USER_NOTIFICATION_UI_FLAG, { isUpdating: false }],
|
|
]);
|
|
});
|
|
it('sends correct actions if API is error', async () => {
|
|
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
|
await expect(
|
|
actions.update(
|
|
{ commit },
|
|
{ selected_email_flags: ['conversation_creation'] }
|
|
)
|
|
).rejects.toEqual({
|
|
message: 'Incorrect header',
|
|
});
|
|
expect(commit.mock.calls).toEqual([
|
|
[types.default.SET_USER_NOTIFICATION_UI_FLAG, { isUpdating: true }],
|
|
[types.default.SET_USER_NOTIFICATION_UI_FLAG, { isUpdating: false }],
|
|
]);
|
|
});
|
|
});
|
|
});
|