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', () => { diff --git a/packages/datagateway-download/src/downloadApiHooks.ts b/packages/datagateway-download/src/downloadApiHooks.ts index 1815ad4ba..cd42e405c 100644 --- a/packages/datagateway-download/src/downloadApiHooks.ts +++ b/packages/datagateway-download/src/downloadApiHooks.ts @@ -542,6 +542,8 @@ export const useDownloadTypeStatuses = ({ if (error) handleQueryError(type); }, ...queryOptions, + cacheTime: 0, + staleTime: 0, })); // I have spent hours on this trying to make the type work,