From 09948d15b2b64aeb37060ea5e5c017af015f0d9f Mon Sep 17 00:00:00 2001 From: NogaNHS Date: Tue, 15 Oct 2024 13:43:06 +0100 Subject: [PATCH] PRMP-935 jest unit tests --- app/src/helpers/requests/getLloydGeorgeRecord.ts | 2 ++ app/src/helpers/requests/getPresignedUrlForZip.test.ts | 4 ++-- app/src/helpers/requests/uploadDocument.test.ts | 2 +- app/src/helpers/test/testBuilders.ts | 2 +- app/src/helpers/utils/isLocal.ts | 2 +- .../lloydGeorgeRecordPage/LloydGeorgeRecordPage.test.tsx | 6 +++--- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/helpers/requests/getLloydGeorgeRecord.ts b/app/src/helpers/requests/getLloydGeorgeRecord.ts index d60413448..11c276b1d 100644 --- a/app/src/helpers/requests/getLloydGeorgeRecord.ts +++ b/app/src/helpers/requests/getLloydGeorgeRecord.ts @@ -63,6 +63,7 @@ export const requestStitchJob = async ({ patientId: nhsNumber, }, }); + return response.data.jobStatus; }; export const pollForPresignedUrl = async ({ @@ -71,6 +72,7 @@ export const pollForPresignedUrl = async ({ baseHeaders, }: Args): Promise => { const gatewayUrl = baseUrl + endpoints.LLOYDGEORGE_STITCH; + const { data } = await axios.get(gatewayUrl, { headers: { ...baseHeaders, diff --git a/app/src/helpers/requests/getPresignedUrlForZip.test.ts b/app/src/helpers/requests/getPresignedUrlForZip.test.ts index 4b5c484e4..cd0dc0aeb 100644 --- a/app/src/helpers/requests/getPresignedUrlForZip.test.ts +++ b/app/src/helpers/requests/getPresignedUrlForZip.test.ts @@ -90,7 +90,7 @@ describe('getPresignedUrlForZip', () => { }); expect(mockWaitForSeconds).toHaveBeenCalledTimes(1); - expect(mockWaitForSeconds).toHaveBeenCalledWith(10); + expect(mockWaitForSeconds).toHaveBeenCalledWith(0); }); it('wait for 10 secs between every polling', async () => { @@ -108,7 +108,7 @@ describe('getPresignedUrlForZip', () => { }); expect(mockWaitForSeconds).toHaveBeenCalledTimes(4); - expect(mockWaitForSeconds).toHaveBeenCalledWith(10); + expect(mockWaitForSeconds).toHaveBeenCalledWith(0); }); it('throw an error if got pending status for 3 times', async () => { diff --git a/app/src/helpers/requests/uploadDocument.test.ts b/app/src/helpers/requests/uploadDocument.test.ts index 1ff7a8d79..027833f38 100644 --- a/app/src/helpers/requests/uploadDocument.test.ts +++ b/app/src/helpers/requests/uploadDocument.test.ts @@ -98,7 +98,7 @@ describe('virusScanResult', () => { .mockRejectedValueOnce(gatewayTimeoutResponse) .mockResolvedValueOnce(cleanResponse); - const delay_between_retry_in_seconds = 5; + const delay_between_retry_in_seconds = 0; const result = await virusScan(virusScanArgs); diff --git a/app/src/helpers/test/testBuilders.ts b/app/src/helpers/test/testBuilders.ts index c7a2ea857..659e205d3 100644 --- a/app/src/helpers/test/testBuilders.ts +++ b/app/src/helpers/test/testBuilders.ts @@ -130,7 +130,7 @@ const buildSearchResult = (searchResultOverride?: Partial) => { const buildLgSearchResult = () => { const result: LloydGeorgeStitchResult = { - jobStatus: 'Complete', + jobStatus: 'Completed', numberOfFiles: 7, totalFileSizeInByte: 7, lastUpdated: '2023-10-03T09:11:54.618694Z', diff --git a/app/src/helpers/utils/isLocal.ts b/app/src/helpers/utils/isLocal.ts index b37dcd7e0..839a4e3ac 100644 --- a/app/src/helpers/utils/isLocal.ts +++ b/app/src/helpers/utils/isLocal.ts @@ -7,5 +7,5 @@ export const isMock = (err: AxiosError) => isLocal && err.code === 'ERR_NETWORK' export const isRunningInCypress = () => { //@ts-ignore - return Boolean(window?.Cypress); + return Boolean(window?.Cypress) || typeof jest !== 'undefined'; }; diff --git a/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.test.tsx b/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.test.tsx index 2e64dc48b..80b8dbfb3 100644 --- a/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.test.tsx +++ b/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.test.tsx @@ -99,7 +99,7 @@ describe('LloydGeorgeRecordPage', () => { }); }); - xit('calls refreshRecord and updates state when successful', async () => { + it('calls refreshRecord and updates state when successful', async () => { const lgResult = buildLgSearchResult(); mockAxios.post.mockResolvedValue({ data: { jobStatus: 'Complete' } }); mockAxios.get.mockResolvedValue({ data: lgResult }); @@ -184,7 +184,7 @@ describe('LloydGeorgeRecordPage', () => { }); }); - xit('renders initial lg record view with file info when LG record is returned by search', async () => { + it('renders initial lg record view with file info when LG record is returned by search', async () => { const lgResult = buildLgSearchResult(); mockAxios.post.mockResolvedValue({ data: { jobStatus: 'Pending' } }); @@ -207,7 +207,7 @@ describe('LloydGeorgeRecordPage', () => { }); describe('Accessibility', () => { - xit('pass accessibility checks at page entry point', async () => { + it('pass accessibility checks at page entry point', async () => { const lgResult = buildLgSearchResult(); mockAxios.post.mockResolvedValue({ data: { jobStatus: 'Pending' } });