From 29415571e9d903aa389480e2c8f1e22ded39a14d Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 6 Apr 2023 20:18:51 +0530 Subject: [PATCH] fix: specs for labels and inboxes --- .../store/modules/specs/inboxes/actions.spec.js | 14 +++++++++++++- .../store/modules/specs/labels/actions.spec.js | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/javascript/dashboard/store/modules/specs/inboxes/actions.spec.js b/app/javascript/dashboard/store/modules/specs/inboxes/actions.spec.js index 381c785e4..fb8ce3abf 100644 --- a/app/javascript/dashboard/store/modules/specs/inboxes/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/inboxes/actions.spec.js @@ -10,7 +10,19 @@ jest.mock('axios'); describe('#actions', () => { describe('#get', () => { 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 }); expect(commit.mock.calls).toEqual([ [types.default.SET_INBOXES_UI_FLAG, { isFetching: true }], diff --git a/app/javascript/dashboard/store/modules/specs/labels/actions.spec.js b/app/javascript/dashboard/store/modules/specs/labels/actions.spec.js index d6d7e63a9..0918949ef 100644 --- a/app/javascript/dashboard/store/modules/specs/labels/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/labels/actions.spec.js @@ -10,7 +10,19 @@ jest.mock('axios'); describe('#actions', () => { describe('#get', () => { 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 }); expect(commit.mock.calls).toEqual([ [types.default.SET_LABEL_UI_FLAG, { isFetching: true }],