diff --git a/app/cypress/e2e/0-ndr-core-tests/auth_routes/auth_general_browser_states.cy.js b/app/cypress/e2e/0-ndr-core-tests/auth_routes/auth_general_browser_states.cy.js index f31c91792..643531bfa 100644 --- a/app/cypress/e2e/0-ndr-core-tests/auth_routes/auth_general_browser_states.cy.js +++ b/app/cypress/e2e/0-ndr-core-tests/auth_routes/auth_general_browser_states.cy.js @@ -1,5 +1,7 @@ import authPayload from '../../../fixtures/requests/auth/GET_TokenRequest_GP_ADMIN.json'; import { Roles } from '../../../support/roles'; +import dbItem from '../../../fixtures/dynamo-db-items/active-patient.json'; +import searchPatientPayload from '../../../fixtures/requests/GET_SearchPatientLGUpload.json'; describe('Authentication & Authorisation', () => { const baseUrl = Cypress.config('baseUrl'); @@ -86,4 +88,42 @@ describe('Authentication & Authorisation', () => { }, ); }); + + context('Page refresh redirection ', () => { + const workspace = Cypress.env('WORKSPACE'); + dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace); + + const lloydGeorgeRecordUrl = '/patient/lloyd-george-record'; + const verifyUrl = '/patient/verify'; + const patientSearchUrl = '/patient/search'; + + it( + 'Refreshing the browser after searching for a patient will return the user to the patient search page', + { tags: 'regression ', defaultCommandTimeout: 20000 }, + () => { + cy.login(Roles.GP_ADMIN); + cy.visit(patientSearchUrl); + + cy.intercept('GET', '/SearchPatient*', { + statusCode: 200, + body: searchPatientPayload, + }).as('search'); + cy.intercept('POST', '/LloydGeorgeStitch*', { + statusCode: 404, + }).as('stitch'); + + cy.getByTestId('nhs-number-input').type(searchPatientPayload.nhsNumber); + cy.getByTestId('search-submit-btn').click(); + + cy.url().should('contain', verifyUrl); + cy.get('#verify-submit').click(); + + cy.url().should('contain', lloydGeorgeRecordUrl); + + cy.reload(); + + cy.url().should('contain', patientSearchUrl); + }, + ); + }); }); diff --git a/app/src/components/blocks/_lloydGeorge/lloydGeorgeDownloadStage/LloydGeorgeDownloadStage.tsx b/app/src/components/blocks/_lloydGeorge/lloydGeorgeDownloadStage/LloydGeorgeDownloadStage.tsx index ae802cba1..2e0580fea 100644 --- a/app/src/components/blocks/_lloydGeorge/lloydGeorgeDownloadStage/LloydGeorgeDownloadStage.tsx +++ b/app/src/components/blocks/_lloydGeorge/lloydGeorgeDownloadStage/LloydGeorgeDownloadStage.tsx @@ -97,6 +97,10 @@ function LloydGeorgeDownloadStage({ const onPageLoad = async () => { progressTimer.stop(); window.clearInterval(intervalTimer); + if (!nhsNumber) { + navigate(routes.SEARCH_PATIENT); + return; + } try { const preSignedUrl = await getPresignedUrlForZip({ baseUrl, diff --git a/app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectDownloadStage/LloydGeorgeSelectDownloadStage.tsx b/app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectDownloadStage/LloydGeorgeSelectDownloadStage.tsx index b47fbd178..c9f43495d 100644 --- a/app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectDownloadStage/LloydGeorgeSelectDownloadStage.tsx +++ b/app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectDownloadStage/LloydGeorgeSelectDownloadStage.tsx @@ -85,6 +85,10 @@ function LloydGeorgeSelectDownloadStage({ useEffect(() => { const onPageLoad = async () => { setSubmissionSearchState(SEARCH_AND_DOWNLOAD_STATE.SEARCH_PENDING); + if (!nhsNumber) { + navigate(routes.SEARCH_PATIENT); + return; + } try { // This check is in place for when we navigate directly to a full download, // in that instance we do not need to get a list of selectable files as we will download all files diff --git a/app/src/router/guards/patientGuard/PatientGuard.test.tsx b/app/src/router/guards/patientGuard/PatientGuard.test.tsx index 8e6154eba..07b8c4720 100644 --- a/app/src/router/guards/patientGuard/PatientGuard.test.tsx +++ b/app/src/router/guards/patientGuard/PatientGuard.test.tsx @@ -19,13 +19,13 @@ describe('AuthGuard', () => { afterEach(() => { jest.clearAllMocks(); }); - it('navigates user to unauthorised when no patient is searched', async () => { + it('navigates user to search patient page when no patient details are stored', async () => { mockedUsePatient.mockReturnValue(null); renderGuard(); await waitFor(async () => { - expect(mockedUseNavigate).toHaveBeenCalledWith(routes.UNAUTHORISED); + expect(mockedUseNavigate).toHaveBeenCalledWith(routes.SEARCH_PATIENT); }); }); diff --git a/app/src/router/guards/patientGuard/PatientGuard.tsx b/app/src/router/guards/patientGuard/PatientGuard.tsx index 9cbd3d953..6a1009872 100644 --- a/app/src/router/guards/patientGuard/PatientGuard.tsx +++ b/app/src/router/guards/patientGuard/PatientGuard.tsx @@ -12,7 +12,7 @@ function PatientGuard({ children }: Props) { const navigate = useNavigate(); useEffect(() => { if (!patient) { - navigate(routes.UNAUTHORISED); + navigate(routes.SEARCH_PATIENT); } }, [patient, navigate]); return <>{children};