Skip to content

Commit

Permalink
Fix tests broken by either renamed varible not being renamed properly…
Browse files Browse the repository at this point in the history
… or module mock implementation being outdated
  • Loading branch information
louise-davies committed Sep 25, 2024
1 parent 6259343 commit bbd11c6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions packages/datagateway-common/src/api/retryICATErrors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AxiosError } from 'axios';
import { useQueryClient } from 'react-query';

export const createRetryICATErrors = (
const createRetryICATErrors = (
retries: number
): ((failureCount: number, error: AxiosError) => boolean) => {
return (failureCount: number, error: AxiosError) =>
Expand All @@ -26,17 +26,20 @@ const baseRetryICATErrors = (
return true;
};

const useRetryICATErrors = (): ((
export const useRetryICATErrors = (): ((
failureCount: number,
error: AxiosError
) => boolean) => {
const queryClient = useQueryClient();
const opts = queryClient.getDefaultOptions();
// TODO: do we want to be more elegant in handling other types of retry...
const retries =
typeof opts.queries?.retry === 'number' ? opts.queries.retry : 3;
typeof opts.queries?.retry === 'number'
? opts.queries.retry
: // explicitly handle boolean case as we set this in tests
opts.queries?.retry === false
? 0

Check warning on line 41 in packages/datagateway-common/src/api/retryICATErrors.ts

View check run for this annotation

Codecov / codecov/patch

packages/datagateway-common/src/api/retryICATErrors.ts#L41

Added line #L41 was not covered by tests
: 3;

return createRetryICATErrors(retries);
};

export { useRetryICATErrors };
2 changes: 1 addition & 1 deletion packages/datagateway-common/src/setupTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ setLogger({
// mock retry function to ensure it doesn't slow down query failure tests
jest.mock('./api/retryICATErrors', () => ({
__esModule: true,
default: jest.fn().mockReturnValue(false),
useRetryICATErrors: jest.fn(() => () => false),
}));

// Mock Date.toLocaleDateString so that it always uses en-GB as locale and UTC timezone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Actions', () => {
features: {},
idsUrl: 'ids',
apiUrl: 'api',
retries: 1,
queryRetries: 1,
breadcrumbs: [
{
matchEntity: 'test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Actions', () => {
apiUrl: 'api',
downloadApiUrl: 'download-api',
icatUrl: 'icat',
retries: 0,
queryRetries: 0,
selectAllSetting: false,
searchableEntities: ['investigation', 'dataset', 'datafile'],
maxNumResults: 150,
Expand Down

0 comments on commit bbd11c6

Please sign in to comment.