Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Dec 7, 2023
1 parent 8eac9cb commit 830c991
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/taxonomy/import-tags/__mocks__/index.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions src/taxonomy/import-tags/__mocks__/tagImportMock.js

This file was deleted.

23 changes: 19 additions & 4 deletions src/taxonomy/import-tags/data/api.test.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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({
Expand All @@ -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));
});
});
});

0 comments on commit 830c991

Please sign in to comment.