Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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);
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/src/router/guards/patientGuard/PatientGuard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
2 changes: 1 addition & 1 deletion app/src/router/guards/patientGuard/PatientGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}</>;
Expand Down
Loading