Skip to content

Commit

Permalink
PRMDR 729 - Upload Smoke (#340)
Browse files Browse the repository at this point in the history
Add Lg upload journey smoke tests
  • Loading branch information
RioKnightleyNHS authored Apr 17, 2024
1 parent 29c4496 commit 51db542
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig({
WORKSPACE: process.env.CYPRESS_WORKSPACE ?? 'local',
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
AWS_REGION: process.env.AWS_REGION,
AWS_REGION: process.env.AWS_REGION ?? 'eu-west-2',
AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN,
},
component: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const testUploadCompletePageContent = () => {

const uploadedFilePathNames = {
LG: [
'cypress/fixtures/lg-files/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/testy_test/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
[
'cypress/fixtures/lg-files/1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/testy_test/1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/testy_test/2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
],
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ const uploadedFilePathNames = {
],
],
LG: [
'cypress/fixtures/lg-files/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/testy_test/1of1_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
[
'cypress/fixtures/lg-files/1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/testy_test/1of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
'cypress/fixtures/lg-files/testy_test/2of2_Lloyd_George_Record_[Testy Test]_[0123456789]_[01-01-2011].pdf',
],
],
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { pdsPatients } from '../../../support/patients';
import { pdsPatients, stubPatients } from '../../../support/patients';
import { Roles } from '../../../support/roles';
import dbItem from '../../../fixtures/dynamo-db-items/active-patient.json';

const workspace = Cypress.env('WORKSPACE');
dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace);
const activePatient = pdsPatients.activeUpload;
const activePatient =
workspace === 'ndr-dev' ? pdsPatients.activeUpload : stubPatients.activeUpload;
const bucketName = `${workspace}-lloyd-george-store`;
const tableName = `${workspace}_LloydGeorgeReferenceMetadata`;
const fileName = `${activePatient}/e4a6d7f7-01f3-44be-8964-515b2c0ec180`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('GP Workflow: Patient search and verify', () => {

const workspace = Cypress.env('WORKSPACE');
const activePatient =
workspace === 'ndr-dev' ? pdsPatients.activeUpload : stubPatients.activeNoUpload;
workspace === 'ndr-dev' ? pdsPatients.activeUpload : stubPatients.activeUpload;
const homeUrl = '/home';
const verifyPatientUrl = '/search/patient/verify';
const lloydGeorgeUrl = '/patient/view/lloyd-george-record';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { pdsPatients, stubPatients } from '../../../support/patients';
import { Roles } from '../../../support/roles';

const workspace = Cypress.env('WORKSPACE');
const uploadedFilePathNames = [
'cypress/fixtures/lg-files/jane_smith/1of3_Lloyd_George_Record_[Jane Smith]_[9000000004]_[22-10-2010].pdf',
'cypress/fixtures/lg-files/jane_smith/2of3_Lloyd_George_Record_[Jane Smith]_[9000000004]_[22-10-2010].pdf',
'cypress/fixtures/lg-files/jane_smith/3of3_Lloyd_George_Record_[Jane Smith]_[9000000004]_[22-10-2010].pdf',
];
const uploadedFileNames = [
'1of3_Lloyd_George_Record_[Jane Smith]_[9000000004]_[22-10-2010].pdf',
'2of3_Lloyd_George_Record_[Jane Smith]_[9000000004]_[22-10-2010].pdf',
'3of3_Lloyd_George_Record_[Jane Smith]_[9000000004]_[22-10-2010].pdf',
];
const viewLloydGeorgeRecordUrl = '/patient/view/lloyd-george-record';
const baseUrl = Cypress.config('baseUrl');
const tableName = `${workspace}_LloydGeorgeReferenceMetadata`;

const activePatient =
workspace === 'ndr-dev' ? pdsPatients.activeNoUploadBsol : stubPatients.activeNoUploadBsol;

describe('GP Workflow: Upload Lloyd George record', () => {
context('Upload a Lloyd George document', () => {
it(
'[Smoke] BSOL GP ADMIN can upload and then view a Lloyd George record for an active patient with no record',
{ tags: 'smoke', defaultCommandTimeout: 20000 },
() => {
cy.smokeLogin(Roles.GP_ADMIN_BSOL);

cy.get('#nhs-number-input').should('exist');
cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(activePatient);
cy.getByTestId('search-submit-btn').should('exist');
cy.getByTestId('search-submit-btn').click();

cy.url({ timeout: 15000 }).should('contain', '/search/patient/verify');

cy.get('#verify-submit').should('exist');
cy.get('#verify-submit').click();

cy.url().should('contain', '/patient/view/lloyd-george-record');
cy.getByTestId('upload-patient-record-text').should(
'include.text',
'You can upload full or part of a patient record',
);
cy.getByTestId('upload-patient-record-button').should('exist');
cy.getByTestId('upload-patient-record-button').click();
uploadedFilePathNames.forEach((file) => {
cy.getByTestId('button-input').selectFile(file, { force: true });
});
cy.get('#upload-button').click();
uploadedFileNames.forEach((name) => {
cy.getByTestId('upload-documents-table').should('contain', name);
});
cy.getByTestId('upload-complete-page', { timeout: 20000 }).should('exist');
cy.getByTestId('upload-complete-page')
.should('include.text', 'Record uploaded for')
.should(
'include.text',
`You have successfully uploaded ${uploadedFileNames.length} files`,
)
.should('include.text', 'Hide files');

uploadedFileNames.forEach((name) => {
cy.getByTestId('upload-complete-page').should('contain', name);
cy.getByTestId(name.split('_')[0])
.invoke('attr', 'data-ref')
.then((ref) => {
cy.deleteItemFromDynamoDb(tableName, ref);
});
});
cy.getByTestId('upload-complete-card').should('be.visible');
cy.getByTestId('view-record-btn').should('be.visible');
cy.getByTestId('search-patient-btn').should('be.visible');
cy.getByTestId('view-record-btn').should('be.visible');
cy.getByTestId('view-record-btn').click();
cy.url().should('eq', baseUrl + viewLloydGeorgeRecordUrl);
},
);
});
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions app/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Cypress.Commands.add('smokeLogin', (role) => {
const password = Cypress.env('PASSWORD');

const startUrl = '/';
const homeUrl = '/home';
const authCallback = '/auth-callback';
cy.visit(startUrl);
cy.getByTestId('start-btn').should('exist');
Expand Down Expand Up @@ -84,7 +83,7 @@ Cypress.Commands.add('smokeLogin', (role) => {
},
);
cy.url().should('contain', baseUrl + authCallback);
cy.url({ timeout: 10000 }).should('contain', baseUrl + homeUrl);
cy.url({ timeout: 15000 }).should('not.contain', baseUrl + authCallback);
} else {
throw new Error("Invalid role for login. Only 'gp' or 'pcse' are allowed.");
}
Expand Down
5 changes: 3 additions & 2 deletions app/cypress/support/patients.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export const pdsPatients = {
activeUpload: 9730153817,
activeNoUploadBsol: 9730787077,
};

export const stubPatients = {
activeNoUpload: 9000000002,
activeUpload: 9730153817,
activeNoUploadBsol: 9000000004,
};
1 change: 1 addition & 0 deletions app/cypress/support/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum Roles {
'GP_ADMIN' = 555053928105,
'GP_CLINICAL' = 555053929106,
'PCSE' = 555053983103,
'GP_ADMIN_BSOL' = 555056255109,
'SMOKE_GP_CLINICAL_H85686' = 555054036108, // anything prefixed with smoke shouldnt be used for cy.login
'SMOKE_GP_ADMIN_H85686' = 555054037109,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ const DocumentsListView = ({ documentsList, ariaLabel }: Props) => {
<Details.Text>
<ul className="document-list-view-list">
{documentsList.map((document) => {
return <li key={document.id}>{document.file.name}</li>;
return (
<li
key={document.id}
data-ref={document.ref}
data-testid={document.file.name.split('_')[0]}
>
{document.file.name}
</li>
);
})}
</ul>
</Details.Text>
Expand Down
5 changes: 1 addition & 4 deletions app/src/helpers/requests/uploadDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type DocRefResponse = {
type UpdateStateArgs = {
document: UploadDocument;
uploadingState: boolean;
documentReference: string;
baseUrl: string;
baseHeaders: AuthHeaders;
};
Expand Down Expand Up @@ -191,16 +190,14 @@ const uploadDocuments = async ({
export const updateDocumentState = async ({
document,
uploadingState,
documentReference,
baseUrl,
baseHeaders,
}: UpdateStateArgs) => {
const fileKey = documentReference.split('/')[3];
const updateUploadStateUrl = baseUrl + endpoints.UPLOAD_DOCUMENT_STATE;
const body = {
files: [
{
reference: fileKey,
reference: document.ref,
type: document.docType,
fields: { Uploading: uploadingState },
},
Expand Down
37 changes: 20 additions & 17 deletions app/src/pages/lloydGeorgeUploadPage/LloydGeorgeUploadPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ type UpdateDocumentArgs = {
state: DOCUMENT_UPLOAD_STATE;
progress?: number | 'scan';
attempts?: number;
ref?: string;
};

export const setDocument = (
setDocuments: Dispatch<SetStateAction<UploadDocument[]>>,
{ id, state, progress, attempts }: UpdateDocumentArgs,
{ id, state, progress, attempts, ref }: UpdateDocumentArgs,
) => {
setDocuments((prevState) =>
prevState.map((document) => {
Expand All @@ -52,6 +53,7 @@ export const setDocument = (
}
attempts = attempts ?? document.attempts;
state = state ?? document.state;
ref = ref ?? document.ref;

return { ...document, state, progress, attempts };
}
Expand Down Expand Up @@ -80,7 +82,6 @@ function LloydGeorgeUploadPage() {

const confirmUpload = async () => {
if (uploadSession) {
window.clearInterval(intervalTimer);
setStage(LG_UPLOAD_STAGE.CONFIRMATION);
try {
const confirmDocumentState = await uploadConfirmation({
Expand Down Expand Up @@ -141,11 +142,7 @@ function LloydGeorgeUploadPage() {
uploadDocuments: Array<UploadDocument>,
uploadSession: UploadSession,
) => {
const updateStateInterval = startIntervalTimer(uploadDocuments, uploadSession);
setIntervalTimer(updateStateInterval);
uploadDocuments.forEach(async (document) => {
const documentMetadata = uploadSession[document.file.name];
const documentReference = documentMetadata.fields.key;
try {
await uploadDocumentToS3({ setDocuments, document, uploadSession });
setDocument(setDocuments, {
Expand All @@ -154,7 +151,7 @@ function LloydGeorgeUploadPage() {
progress: 'scan',
});
const virusDocumentState = await virusScanResult({
documentReference,
documentReference: document.key ?? '',
baseUrl,
baseHeaders,
});
Expand All @@ -164,7 +161,7 @@ function LloydGeorgeUploadPage() {
progress: 100,
});
} catch (e) {
window.clearInterval(updateStateInterval);
window.clearInterval(intervalTimer);
setDocument(setDocuments, {
id: document.id,
state: DOCUMENT_UPLOAD_STATE.FAILED,
Expand All @@ -174,7 +171,6 @@ function LloydGeorgeUploadPage() {
await updateDocumentState({
document,
uploadingState: false,
documentReference,
baseUrl,
baseHeaders,
});
Expand All @@ -192,7 +188,20 @@ function LloydGeorgeUploadPage() {
baseHeaders,
});
setUploadSession(uploadSession);
uploadAndScanDocuments(documents, uploadSession);
const uploadingDocuments = documents.map((doc) => {
const documentMetadata = uploadSession[doc.file.name];
const documentReference = documentMetadata.fields.key;
return {
...doc,
state: DOCUMENT_UPLOAD_STATE.UPLOADING,
key: documentReference,
ref: documentReference.split('/')[3],
};
});
const updateStateInterval = startIntervalTimer(uploadingDocuments);
setIntervalTimer(updateStateInterval);
setDocuments(uploadingDocuments);
uploadAndScanDocuments(uploadingDocuments, uploadSession);
} catch (e) {
const error = e as AxiosError;
if (error.response?.status === 403) {
Expand Down Expand Up @@ -224,19 +233,13 @@ function LloydGeorgeUploadPage() {
setDocuments([]);
setStage(LG_UPLOAD_STAGE.SELECT);
};
const startIntervalTimer = (
uploadDocuments: Array<UploadDocument>,
uploadSession: UploadSession,
) => {
const startIntervalTimer = (uploadDocuments: Array<UploadDocument>) => {
return window.setInterval(() => {
uploadDocuments.forEach(async (document) => {
const documentMetadata = uploadSession[document.file.name];
const documentReference = documentMetadata.fields.key;
try {
await updateDocumentState({
document,
uploadingState: true,
documentReference,
baseUrl,
baseHeaders,
});
Expand Down
2 changes: 2 additions & 0 deletions app/src/types/pages/UploadDocumentsPage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export type UploadDocument = {
id: string;
docType: DOCUMENT_TYPE;
attempts: number;
ref?: string;
key?: string;
};

export type UploadFilesErrors = {
Expand Down

0 comments on commit 51db542

Please sign in to comment.