From 94f1bf72103d7e7414434ba94a5413bcb373b331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Fri, 8 Dec 2023 11:32:25 -0300 Subject: [PATCH] test: fix api test --- src/taxonomy/import-tags/data/api.test.jsx | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/taxonomy/import-tags/data/api.test.jsx b/src/taxonomy/import-tags/data/api.test.jsx index 0f7d43aaa6..ae0a56ae11 100644 --- a/src/taxonomy/import-tags/data/api.test.jsx +++ b/src/taxonomy/import-tags/data/api.test.jsx @@ -26,6 +26,16 @@ const queryClient = new QueryClient({ }, }); +const mockInvalidateQueries = jest.fn(); + +jest.mock('@tanstack/react-query', () => ({ + ...jest.requireActual('@tanstack/react-query'), + useQueryClient: () => ({ + ...jest.requireActual('@tanstack/react-query').useQueryClient(), + invalidateQueries: mockInvalidateQueries, + }), +})); + const wrapper = ({ children }) => ( {children} @@ -69,5 +79,18 @@ describe('import taxonomy api calls', () => { axiosMock.onPut(getTagsPlanImportApiUrl(1)).reply(200, { plan: 'plan' }); await planImportTags(1); expect(axiosMock.history.put[0].url).toEqual(getTagsPlanImportApiUrl(1)); + expect(mockInvalidateQueries).toHaveBeenCalledWith({ + queryKey: ['tagList', 1], + }); + expect(mockInvalidateQueries).toHaveBeenCalledWith({ + queryKey: ['taxonomyDetail', 1], + }); + }); + + it('should handle errors in plan import tags', async () => { + axiosMock.onPut(getTagsPlanImportApiUrl(1)).reply(400, { error: 'test error' }); + expect(planImportTags(1)).rejects.toEqual(Error('test error')); + expect(axiosMock.history.put[0].url).toEqual(getTagsPlanImportApiUrl(1)); + expect(mockInvalidateQueries).not.toHaveBeenCalled(); }); });