Skip to content

Commit

Permalink
test: fix api test
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Dec 8, 2023
1 parent cb52fd7 commit 94f1bf7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/taxonomy/import-tags/data/api.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<QueryClientProvider client={queryClient}>
{children}
Expand Down Expand Up @@ -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();
});
});

0 comments on commit 94f1bf7

Please sign in to comment.