fix: Specs failing for teams/actions.js (#6845)

* fix: specs failing

* fix: specs for labels and inboxes

* Update reports.js

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Shivam Mishra
2023-04-06 20:48:49 +05:30
committed by GitHub
parent 37dd898c9a
commit 406e8405eb
4 changed files with 40 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ import { REPORTS_EVENTS } from '../../helper/AnalyticsHelper/events';
import { import {
reconcileHeatmapData, reconcileHeatmapData,
clampDataBetweenTimeline, clampDataBetweenTimeline,
} from 'helpers/ReportsDataHelper'; } from 'shared/helpers/ReportsDataHelper';
const state = { const state = {
fetchingStatus: false, fetchingStatus: false,

View File

@@ -10,7 +10,19 @@ jest.mock('axios');
describe('#actions', () => { describe('#actions', () => {
describe('#get', () => { describe('#get', () => {
it('sends correct actions if API is success', async () => { it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue({ data: { payload: inboxList } }); const mockedGet = jest.fn(url => {
if (url === '/api/v1/inboxes') {
return Promise.resolve({ data: { payload: inboxList } });
}
if (url === '/api/v1/accounts//cache_keys') {
return Promise.resolve({ data: { cache_keys: { inboxes: 0 } } });
}
// Return default value or throw an error for unexpected requests
return Promise.reject(new Error('Unexpected request: ' + url));
});
axios.get = mockedGet;
await actions.get({ commit }); await actions.get({ commit });
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
[types.default.SET_INBOXES_UI_FLAG, { isFetching: true }], [types.default.SET_INBOXES_UI_FLAG, { isFetching: true }],

View File

@@ -10,7 +10,19 @@ jest.mock('axios');
describe('#actions', () => { describe('#actions', () => {
describe('#get', () => { describe('#get', () => {
it('sends correct actions if API is success', async () => { it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue({ data: { payload: labelsList } }); const mockedGet = jest.fn(url => {
if (url === '/api/v1/labels') {
return Promise.resolve({ data: { payload: labelsList } });
}
if (url === '/api/v1/accounts//cache_keys') {
return Promise.resolve({ data: { cache_keys: { labels: 0 } } });
}
// Return default value or throw an error for unexpected requests
return Promise.reject(new Error('Unexpected request: ' + url));
});
axios.get = mockedGet;
await actions.get({ commit }); await actions.get({ commit });
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
[types.default.SET_LABEL_UI_FLAG, { isFetching: true }], [types.default.SET_LABEL_UI_FLAG, { isFetching: true }],

View File

@@ -17,7 +17,19 @@ jest.mock('axios');
describe('#actions', () => { describe('#actions', () => {
describe('#get', () => { describe('#get', () => {
it('sends correct actions if API is success', async () => { it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue({ data: teamsList[1] }); const mockedGet = jest.fn(url => {
if (url === '/api/v1/teams') {
return Promise.resolve({ data: teamsList[1] });
}
if (url === '/api/v1/accounts//cache_keys') {
return Promise.resolve({ data: { cache_keys: { teams: 0 } } });
}
// Return default value or throw an error for unexpected requests
return Promise.reject(new Error('Unexpected request: ' + url));
});
axios.get = mockedGet;
await actions.get({ commit }); await actions.get({ commit });
expect(commit.mock.calls).toEqual([ expect(commit.mock.calls).toEqual([
[SET_TEAM_UI_FLAG, { isFetching: true }], [SET_TEAM_UI_FLAG, { isFetching: true }],