diff --git a/packages/core/upload/admin/src/hooks/tests/useBulkRemove.test.js b/packages/core/upload/admin/src/hooks/tests/useBulkRemove.test.js index dbaabc49fb..4b6ec15876 100644 --- a/packages/core/upload/admin/src/hooks/tests/useBulkRemove.test.js +++ b/packages/core/upload/admin/src/hooks/tests/useBulkRemove.test.js @@ -4,9 +4,8 @@ import { QueryClientProvider, QueryClient, useQueryClient } from 'react-query'; import { renderHook, act } from '@testing-library/react-hooks'; import { BrowserRouter as Router, Route } from 'react-router-dom'; -import { NotificationsProvider, useNotification } from '@strapi/helper-plugin'; +import { NotificationsProvider, useNotification, useFetchClient } from '@strapi/helper-plugin'; -import { axiosInstance } from '../../utils'; import { useBulkRemove } from '../useBulkRemove'; const FIXTURE_ASSETS = [ @@ -33,9 +32,12 @@ const FIXTURE_FOLDERS = [ }, ]; -jest.mock('../../utils', () => ({ - ...jest.requireActual('../../utils'), - axiosInstance: { +const notificationStatusMock = jest.fn(); + +jest.mock('@strapi/helper-plugin', () => ({ + ...jest.requireActual('@strapi/helper-plugin'), + useNotification: () => notificationStatusMock, + useFetchClient: jest.fn().mockReturnValue({ post: jest.fn((url, payload) => { const res = { data: { data: {} } }; @@ -49,14 +51,7 @@ jest.mock('../../utils', () => ({ return Promise.resolve(res); }), - }, -})); - -const notificationStatusMock = jest.fn(); - -jest.mock('@strapi/helper-plugin', () => ({ - ...jest.requireActual('@strapi/helper-plugin'), - useNotification: () => notificationStatusMock, + }), })); const refetchQueriesMock = jest.fn(); @@ -111,15 +106,13 @@ describe('useBulkRemove', () => { result: { current }, } = await setup(); const { remove } = current; + const { post } = useFetchClient(); await act(async () => { await remove(FIXTURE_ASSETS); }); - expect(axiosInstance.post).toHaveBeenCalledWith( - '/upload/actions/bulk-delete', - expect.any(Object) - ); + expect(post).toHaveBeenCalledWith('/upload/actions/bulk-delete', expect.any(Object)); }); test('does properly collect all asset ids', async () => { @@ -127,12 +120,13 @@ describe('useBulkRemove', () => { result: { current }, } = await setup(); const { remove } = current; + const { post } = useFetchClient(); await act(async () => { await remove(FIXTURE_ASSETS); }); - expect(axiosInstance.post).toHaveBeenCalledWith(expect.any(String), { + expect(post).toHaveBeenCalledWith(expect.any(String), { fileIds: FIXTURE_ASSETS.map(({ id }) => id), }); }); @@ -142,12 +136,13 @@ describe('useBulkRemove', () => { result: { current }, } = await setup(); const { remove } = current; + const { post } = useFetchClient(); await act(async () => { await remove(FIXTURE_FOLDERS); }); - expect(axiosInstance.post).toHaveBeenCalledWith(expect.any(String), { + expect(post).toHaveBeenCalledWith(expect.any(String), { folderIds: FIXTURE_FOLDERS.map(({ id }) => id), }); }); @@ -157,12 +152,13 @@ describe('useBulkRemove', () => { result: { current }, } = await setup(); const { remove } = current; + const { post } = useFetchClient(); await act(async () => { await remove([...FIXTURE_FOLDERS, ...FIXTURE_ASSETS]); }); - expect(axiosInstance.post).toHaveBeenCalledWith(expect.any(String), { + expect(post).toHaveBeenCalledWith(expect.any(String), { fileIds: FIXTURE_ASSETS.map(({ id }) => id), folderIds: FIXTURE_FOLDERS.map(({ id }) => id), }); diff --git a/packages/core/upload/admin/src/hooks/useBulkRemove.js b/packages/core/upload/admin/src/hooks/useBulkRemove.js index c98102d95f..ba9a75954f 100644 --- a/packages/core/upload/admin/src/hooks/useBulkRemove.js +++ b/packages/core/upload/admin/src/hooks/useBulkRemove.js @@ -1,13 +1,14 @@ import { useMutation, useQueryClient } from 'react-query'; -import { useNotification } from '@strapi/helper-plugin'; +import { useNotification, useFetchClient } from '@strapi/helper-plugin'; import pluginId from '../pluginId'; -import { axiosInstance, getRequestUrl, getTrad } from '../utils'; +import { getRequestUrl, getTrad } from '../utils'; export const useBulkRemove = () => { const toggleNotification = useNotification(); const queryClient = useQueryClient(); const url = getRequestUrl('actions/bulk-delete'); + const { post } = useFetchClient(); const bulkRemoveQuery = (filesAndFolders) => { const payload = filesAndFolders.reduce((acc, selected) => { @@ -23,7 +24,9 @@ export const useBulkRemove = () => { return acc; }, {}); - return axiosInstance.post(url, payload); + console.log('useBulkRemove new', url); + + return post(url, payload); }; const mutation = useMutation(bulkRemoveQuery, {