diff --git a/src/taxonomy/import-tags/__mocks__/index.js b/src/taxonomy/import-tags/__mocks__/index.js index ba0b48ccb9..78ef2f5e8f 100644 --- a/src/taxonomy/import-tags/__mocks__/index.js +++ b/src/taxonomy/import-tags/__mocks__/index.js @@ -1,2 +1 @@ -export { default as taxonomyImportMock } from './taxonomyImportMock'; -export { default as tagImportMock } from './tagImportMock'; +export { default as taxonomyImportMock } from './taxonomyImportMock'; // eslint-disable-line import/prefer-default-export diff --git a/src/taxonomy/import-tags/__mocks__/tagImportMock.js b/src/taxonomy/import-tags/__mocks__/tagImportMock.js deleted file mode 100644 index 9db45b4a5e..0000000000 --- a/src/taxonomy/import-tags/__mocks__/tagImportMock.js +++ /dev/null @@ -1,4 +0,0 @@ -export default { - name: 'Taxonomy name', - description: 'Taxonomy description', -}; diff --git a/src/taxonomy/import-tags/data/api.test.js b/src/taxonomy/import-tags/data/api.test.js index 47ba167ab4..d0e2bbab34 100644 --- a/src/taxonomy/import-tags/data/api.test.js +++ b/src/taxonomy/import-tags/data/api.test.js @@ -1,8 +1,10 @@ import { initializeMockApp } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; +import { useMutation } from '@tanstack/react-query'; +import { act } from '@testing-library/react'; import MockAdapter from 'axios-mock-adapter'; -import { tagImportMock, taxonomyImportMock } from '../__mocks__'; +import { taxonomyImportMock } from '../__mocks__'; import { getTaxonomyImportNewApiUrl, @@ -13,6 +15,11 @@ import { let axiosMock; +jest.mock('@tanstack/react-query', () => ({ + useMutation: jest.fn(), + useQueryClient: jest.fn(), +})); + describe('import taxonomy api calls', () => { beforeEach(() => { initializeMockApp({ @@ -39,10 +46,18 @@ describe('import taxonomy api calls', () => { }); it('should call import tags', async () => { - axiosMock.onPut(getTagsImportApiUrl(1)).reply(200, tagImportMock); + axiosMock.onPut(getTagsImportApiUrl(1)).reply(200); + useMutation.mockReturnValueOnce({ mutate: jest.fn() }); + const mutation = useImportTags(); - mutation.mutate(1); + mutation.mutate({ taxonomyId: 1 }); - expect(axiosMock.history.put[0].url).toEqual(getTagsImportApiUrl(1)); + const [config] = useMutation.mock.calls[0]; + const { mutationFn } = config; + + await act(async () => { + await mutationFn({ taxonomyId: 1 }); + expect(axiosMock.history.put[0].url).toEqual(getTagsImportApiUrl(1)); + }); }); });