From c684bc73d4bd8188bd7a79c32c01766bffe98a4c Mon Sep 17 00:00:00 2001 From: Gustav Hansen Date: Thu, 5 May 2022 22:42:35 +0200 Subject: [PATCH] useEditFolder: Fix and improve tests --- .../src/hooks/tests/useEditFolder.test.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/core/upload/admin/src/hooks/tests/useEditFolder.test.js b/packages/core/upload/admin/src/hooks/tests/useEditFolder.test.js index a893a84724..cbedbc05e1 100644 --- a/packages/core/upload/admin/src/hooks/tests/useEditFolder.test.js +++ b/packages/core/upload/admin/src/hooks/tests/useEditFolder.test.js @@ -25,7 +25,7 @@ console.error = jest.fn().mockImplementation(); jest.mock('../../utils', () => ({ ...jest.requireActual('../../utils'), axiosInstance: { - put: jest.fn().mockResolvedValue({ name: 'folder-created' }), + put: jest.fn().mockResolvedValue({ name: 'folder-edited' }), post: jest.fn().mockResolvedValue({ name: 'folder-created' }), }, })); @@ -84,7 +84,7 @@ describe('useEditFolder', () => { jest.clearAllMocks(); }); - test('calls the proper endpoint when creating a folder', async () => { + test('calls the proper endpoint when creating a folder (post)', async () => { const { result: { current }, } = await setup(); @@ -97,6 +97,19 @@ describe('useEditFolder', () => { expect(axiosInstance.post).toHaveBeenCalledWith('/upload/folders', expect.any(Object)); }); + test('calls the proper endpoint when creating a folder (put)', async () => { + const { + result: { current }, + } = await setup(); + const { editFolder } = current; + + await act(async () => { + await editFolder(FOLDER_EDIT_FIXTURE); + }); + + expect(axiosInstance.put).toHaveBeenCalledWith('/upload/folders', expect.any(Object)); + }); + test('calls the proper endpoint when editing a folder', async () => { const { result: { current }, @@ -144,7 +157,7 @@ describe('useEditFolder', () => { }); test('calls toggleNotification in case of an error', async () => { - axiosInstance.post.mockRejectedValue({ message: 'err-test' }); + axiosInstance.put.mockRejectedValue({ message: 'err-test' }); const toggleNotification = useNotification(); const {