From ca2a7bfd2ada01bcb1570e37ff007f1ff175c031 Mon Sep 17 00:00:00 2001 From: Kacper Roemer Date: Wed, 16 Aug 2023 14:43:21 +0100 Subject: [PATCH 1/3] changed cacheTime for status type requests #1519 --- packages/datagateway-download/src/downloadApiHooks.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/datagateway-download/src/downloadApiHooks.ts b/packages/datagateway-download/src/downloadApiHooks.ts index 1815ad4ba..3dbe62452 100644 --- a/packages/datagateway-download/src/downloadApiHooks.ts +++ b/packages/datagateway-download/src/downloadApiHooks.ts @@ -542,6 +542,7 @@ export const useDownloadTypeStatuses = ({ if (error) handleQueryError(type); }, ...queryOptions, + cacheTime: 0, })); // I have spent hours on this trying to make the type work, From fa4fcbc8a8c75ae4fe99437fad3fbea100bddef2 Mon Sep 17 00:00:00 2001 From: Kacper Roemer Date: Thu, 17 Aug 2023 16:13:01 +0100 Subject: [PATCH 2/3] set staleTime to 0 #1519 --- packages/datagateway-download/src/downloadApiHooks.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/datagateway-download/src/downloadApiHooks.ts b/packages/datagateway-download/src/downloadApiHooks.ts index 3dbe62452..cd42e405c 100644 --- a/packages/datagateway-download/src/downloadApiHooks.ts +++ b/packages/datagateway-download/src/downloadApiHooks.ts @@ -543,6 +543,7 @@ export const useDownloadTypeStatuses = ({ }, ...queryOptions, cacheTime: 0, + staleTime: 0, })); // I have spent hours on this trying to make the type work, From 8dc8dd0cb1e951b00ecbc8eae4ca74f903b8901c Mon Sep 17 00:00:00 2001 From: Kacper Roemer Date: Sun, 20 Aug 2023 19:38:58 +0100 Subject: [PATCH 3/3] Tests for download type status caching #1519 --- .../src/downloadApiHooks.test.tsx | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/packages/datagateway-download/src/downloadApiHooks.test.tsx b/packages/datagateway-download/src/downloadApiHooks.test.tsx index 4e828cd9b..0b3ebfac0 100644 --- a/packages/datagateway-download/src/downloadApiHooks.test.tsx +++ b/packages/datagateway-download/src/downloadApiHooks.test.tsx @@ -1151,6 +1151,16 @@ describe('Download Cart API react-query hooks test', () => { describe('useDownloadTypeStatuses', () => { const downloadTypes = ['https', 'globus']; + let queryClient: QueryClient; + + beforeAll(() => { + queryClient = new QueryClient(); + }); + + afterEach(() => { + queryClient.clear(); + }); + it('should query statuses of download types', async () => { axios.get = jest.fn().mockResolvedValue({ data: { @@ -1218,6 +1228,43 @@ describe('Download Cart API react-query hooks test', () => { } ); }); + + it('should refetch data on every hook call', async () => { + axios.get = jest.fn().mockResolvedValue({ + data: { + disabled: false, + message: '', + }, + }); + + const wrapper = createReactQueryWrapper(); + + const { result, waitFor } = renderHook( + () => + useDownloadTypeStatuses({ + downloadTypes: ['https'], + }), + { wrapper } + ); + + await waitFor(() => result.current.every((query) => query.isSuccess)); + + expect(result.current[0].isStale).toBe(true); + expect(axios.get).toHaveBeenCalledTimes(1); + + const { result: newResult } = renderHook( + () => + useDownloadTypeStatuses({ + downloadTypes: ['https'], + }), + { wrapper } + ); + + await waitFor(() => newResult.current.every((query) => query.isSuccess)); + + expect(newResult.current[0].isStale).toBe(true); + expect(axios.get).toHaveBeenCalledTimes(2); + }); }); describe('useDownloadPercentageComplete', () => {