From 03a271b6f0fcbe1903fc135c28185b03ff403089 Mon Sep 17 00:00:00 2001 From: Kamen Bachvarov Date: Thu, 26 Mar 2026 16:00:40 +0000 Subject: [PATCH] [PRMP-1269] Upload ehr and attachments smoke test --- .../add_scanned_paper_notes.cy.js | 4 +- ..._success_as_data_controller_workflow.cy.js | 160 ++++++++++++++++++ .../{simple_pages => simple_pdf_pages}/6.pdf | Bin .../{simple_pages => simple_pdf_pages}/7.pdf | Bin app/cypress/fixtures/non-pdf-files/1.csv | 1 + app/cypress/fixtures/non-pdf-files/2.txt | 1 + app/cypress/support/aws.commands.ts | 26 +++ app/cypress/support/commands.d.ts | 11 +- 8 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/upload_ehr_with_attachments_success_as_data_controller_workflow.cy.js rename app/cypress/fixtures/lg-files/{simple_pages => simple_pdf_pages}/6.pdf (100%) rename app/cypress/fixtures/lg-files/{simple_pages => simple_pdf_pages}/7.pdf (100%) create mode 100644 app/cypress/fixtures/non-pdf-files/1.csv create mode 100644 app/cypress/fixtures/non-pdf-files/2.txt diff --git a/app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/add_scanned_paper_notes.cy.js b/app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/add_scanned_paper_notes.cy.js index fcd40bab5..c81443a11 100644 --- a/app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/add_scanned_paper_notes.cy.js +++ b/app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/add_scanned_paper_notes.cy.js @@ -16,8 +16,8 @@ const confirmationUrl = '/patient/document-upload/confirmation'; dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace); const uploadedFilePathNames = [ - 'cypress/fixtures/lg-files/simple_pages/6.pdf', - 'cypress/fixtures/lg-files/simple_pages/7.pdf', + 'cypress/fixtures/lg-files/simple_pdf_pages/6.pdf', + 'cypress/fixtures/lg-files/simple_pdf_pages/7.pdf', ]; const uploadedFileNames = ['6', '7']; diff --git a/app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/upload_ehr_with_attachments_success_as_data_controller_workflow.cy.js b/app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/upload_ehr_with_attachments_success_as_data_controller_workflow.cy.js new file mode 100644 index 000000000..b8612b07c --- /dev/null +++ b/app/cypress/e2e/1-ndr-smoke-tests/gp_user_workflows/upload_ehr_with_attachments_success_as_data_controller_workflow.cy.js @@ -0,0 +1,160 @@ +import { pdsPatients } from '../../../support/patients'; +import dbItem from '../../../fixtures/dynamo-db-items/active-patient-h81109.json'; +import { Roles } from '../../../support/roles'; + +const workspace = Cypress.env('WORKSPACE'); +const lgTableName = `${workspace}_LloydGeorgeReferenceMetadata`; +const bucketName = `${workspace}-lloyd-george-store`; +const activePatient = pdsPatients.activeUpload; +const filePath = `${activePatient}/`; + +const patientVerifyUrl = '/patient/verify'; +const lloydGeorgeRecordUrl = '/patient/documents'; +const documentUploadUrl = '/patient/document-upload'; +const selectFilesUrl = '/patient/document-upload/select-files'; +const confirmationUrl = '/patient/document-upload/confirmation'; + +dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace); + +const uploadedEhrFilePathName = 'cypress/fixtures/lg-files/simple_pdf_pages/6.pdf'; +const uploadedEhrFileName = '6.pdf'; + +const uploadedEhrAttachmentsFilePathNames = [ + 'cypress/fixtures/non-pdf-files/1.csv', + 'cypress/fixtures/non-pdf-files/2.txt', +]; +const uploadedEhrAttachmentsFileNames = ['1.csv', '2.txt']; + +const expectedRows = [ + { + type: 'Electronic health record', + filename: uploadedEhrFileName, + }, + { + type: 'Electronic health record attachments', + filename: 'EHR_Attachments_(2).zip', + }, +]; + +describe('GP Workflow: Upload EHR with attachments and view them successfully as data controller', () => { + context('Upload EHR with attachments and view them successfully as data controller', () => { + beforeEach(() => { + cy.deleteItemsBySecondaryKeyFromDynamoDb( + lgTableName, + 'NhsNumberIndex', + 'NhsNumber', + activePatient.toString(), + ); + }); + + afterEach(() => { + cy.deleteItemsBySecondaryKeyFromDynamoDb( + lgTableName, + 'NhsNumberIndex', + 'NhsNumber', + activePatient.toString(), + ); + cy.deleteAllFilesFromS3Prefix(bucketName, filePath); + }); + + const roles = [Roles.SMOKE_GP_ADMIN, Roles.SMOKE_GP_CLINICAL]; + + roles.forEach((role) => { + it( + `[Smoke] ${role} can upload EHR with attachments and view them successfully`, + { tags: 'smoke', defaultCommandTimeout: 20000 }, + () => { + cy.smokeLogin(role); + cy.navigateToPatientSearchPage(); + + 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', patientVerifyUrl); + + cy.get('#verify-submit').should('exist'); + cy.get('#verify-submit').click(); + cy.url().should('contain', lloydGeorgeRecordUrl); + + cy.getByTestId('upload-button').click(); + cy.url().should('contain', documentUploadUrl); + + cy.getByTestId('upload-717301000000104-link').should('exist'); + cy.getByTestId('upload-717301000000104-link').click(); + cy.url().should('contain', selectFilesUrl); + + cy.getByTestId('button-input').selectFile(uploadedEhrFilePathName, { + force: true, + }); + cy.get('#selected-documents-table').should('contain', uploadedEhrFileName); + + cy.get('#continue-button').should('exist'); + cy.get('#continue-button').click(); + cy.url().should('contain', selectFilesUrl); + + uploadedEhrAttachmentsFilePathNames.forEach((file) => { + cy.getByTestId('button-input').selectFile(file, { force: true }); + var index = uploadedEhrAttachmentsFilePathNames.indexOf(file); + cy.get('#selected-documents-table').should( + 'contain', + uploadedEhrAttachmentsFileNames[index], + ); + }); + + cy.get('#continue-button').should('exist'); + cy.get('#continue-button').click(); + cy.url().should('contain', confirmationUrl); + cy.get('#selected-717301000000104-table').should( + 'contain', + uploadedEhrFileName, + ); + uploadedEhrAttachmentsFileNames.forEach((file) => { + var index = uploadedEhrAttachmentsFileNames.indexOf(file); + cy.get('#selected-24511000000107-table').should( + 'contain', + uploadedEhrAttachmentsFileNames[index], + ); + }); + cy.getByTestId('confirm-button').should('exist').click(); + + cy.getByTestId('upload-complete-page').should('exist'); + cy.getByTestId('upload-complete-card').should('be.visible'); + + cy.getByTestId('home-btn').should('exist'); + cy.getByTestId('home-btn').eq(1).click(); + cy.navigateToPatientSearchPage(); + + cy.get('#nhs-number-input').type(activePatient); + cy.get('#search-submit').click(); + cy.get('.patient-results-form').should('exist'); + cy.get('.patient-results-form').submit(); + + cy.getByTestId('available-files-table-title').should('exist'); + + cy.get('[data-testid="search-result"]').should( + 'have.length', + expectedRows.length, + ); + + expectedRows.forEach((row, index) => { + cy.get('[data-testid="search-result"]') + .eq(index) + .within(() => { + cy.get('[data-testid="doctype"]').should('contain.text', row.type); + cy.get('[data-testid="filename"]').should( + 'contain.text', + row.filename, + ); + cy.get('[data-testid^="view-"]') + .should('exist') + .and('be.visible') + .and('contain.text', 'View'); + }); + }); + }, + ); + }); + }); +}); diff --git a/app/cypress/fixtures/lg-files/simple_pages/6.pdf b/app/cypress/fixtures/lg-files/simple_pdf_pages/6.pdf similarity index 100% rename from app/cypress/fixtures/lg-files/simple_pages/6.pdf rename to app/cypress/fixtures/lg-files/simple_pdf_pages/6.pdf diff --git a/app/cypress/fixtures/lg-files/simple_pages/7.pdf b/app/cypress/fixtures/lg-files/simple_pdf_pages/7.pdf similarity index 100% rename from app/cypress/fixtures/lg-files/simple_pages/7.pdf rename to app/cypress/fixtures/lg-files/simple_pdf_pages/7.pdf diff --git a/app/cypress/fixtures/non-pdf-files/1.csv b/app/cypress/fixtures/non-pdf-files/1.csv new file mode 100644 index 000000000..56a6051ca --- /dev/null +++ b/app/cypress/fixtures/non-pdf-files/1.csv @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/app/cypress/fixtures/non-pdf-files/2.txt b/app/cypress/fixtures/non-pdf-files/2.txt new file mode 100644 index 000000000..d8263ee98 --- /dev/null +++ b/app/cypress/fixtures/non-pdf-files/2.txt @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/app/cypress/support/aws.commands.ts b/app/cypress/support/aws.commands.ts index bb9efdbbb..041d3ade6 100644 --- a/app/cypress/support/aws.commands.ts +++ b/app/cypress/support/aws.commands.ts @@ -8,6 +8,8 @@ import { DeleteObjectCommand, PutObjectCommandInput, DeleteObjectCommandInput, + ListObjectsV2Command, + ListObjectsV2CommandOutput, } from '@aws-sdk/client-s3'; import { @@ -91,6 +93,30 @@ Cypress.Commands.add('deleteFileFromS3', (bucketName: string, fileName: string) ); }); +Cypress.Commands.add('deleteAllFilesFromS3Prefix', (bucketName: string, prefix: string): void => { + const deleteAllFilesFromS3Prefix = async (): Promise => { + const listResponse: ListObjectsV2CommandOutput = await s3.send( + new ListObjectsV2Command({ + Bucket: bucketName, + Prefix: prefix, + }), + ); + + const keys: string[] = (listResponse.Contents || []).map((obj) => obj.Key!); + + for (const key of keys) { + await s3.send( + new DeleteObjectCommand({ + Bucket: bucketName, + Key: key, + }), + ); + } + }; + + cy.then(() => deleteAllFilesFromS3Prefix()); +}); + Cypress.Commands.add( 'deleteItemFromDynamoDb', (tableName: string, itemId: string, version?: number) => { diff --git a/app/cypress/support/commands.d.ts b/app/cypress/support/commands.d.ts index 28312f39a..5ce2187a4 100644 --- a/app/cypress/support/commands.d.ts +++ b/app/cypress/support/commands.d.ts @@ -1,7 +1,11 @@ // cypress/support/commands.d.ts /// -import type { PutObjectCommandOutput, DeleteObjectCommandOutput } from '@aws-sdk/client-s3'; +import type { + PutObjectCommandOutput, + DeleteObjectCommandOutput, + ListObjectsCommandOutput, +} from '@aws-sdk/client-s3'; import type { PutItemCommandOutput, DeleteItemCommandOutput } from '@aws-sdk/client-dynamodb'; declare global { @@ -25,6 +29,11 @@ declare global { fileName: string, ): Chainable; + deleteAllFilesFromS3Prefix( + bucketName: string, + prefix: string, + ): Chainable; + deleteItemFromDynamoDb( tableName: string, itemId: string,