Skip to content
Open
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
Expand Up @@ -30,7 +30,7 @@ const featureFlags = {

const bucketUrlIdentifier = 'document-store.s3.amazonaws.com';

describe.skip('GP Workflow: Restore document version', () => {
describe('GP Workflow: Restore document version', () => {
const beforeEachConfiguration = (role) => {
cy.login(role, featureFlags);
cy.navigateToPatientSearchPage();
Expand Down Expand Up @@ -66,7 +66,7 @@ describe.skip('GP Workflow: Restore document version', () => {
cy.intercept(
{
method: 'GET',
url: '/DocumentReference/2a7a270e-aa1d-532e-8648-d5d8e3defb82',
url: '/DocumentReference/2a7a270e-aa1d-532e-8648-d5d8e3defb82*',
},
{
statusCode: 200,
Expand Down Expand Up @@ -106,20 +106,16 @@ describe.skip('GP Workflow: Restore document version', () => {
beforeEachConfiguration(Roles.GP_ADMIN);
navigateToVersionHistory();

// Assert version history page is shown
cy.contains('Version history').should('be.visible');

// Assert all 3 versions are displayed
cy.getByTestId('view-version-3').should('exist');
cy.getByTestId('view-version-2').should('exist');
cy.getByTestId('view-version-1').should('exist');

// Assert active version (v3) shows "This is the current version"
cy.contains("This is the current version shown in this patient's record").should(
'be.visible',
);

// Assert inactive versions have "Restore version" links
cy.getByTestId('restore-version-2').should('exist');
cy.getByTestId('restore-version-1').should('exist');
},
Expand All @@ -146,17 +142,14 @@ describe.skip('GP Workflow: Restore document version', () => {
beforeEachConfiguration(Roles.GP_ADMIN);
navigateToRestoreConfirm();

// Assert restore confirm page is shown
cy.contains(
'Are you sure you want to restore this version of these scanned paper notes?',
).should('be.visible');

// Assert radio options are present
cy.getByTestId('yes-radio-btn').should('exist');
cy.getByTestId('no-radio-btn').should('exist');
cy.getByTestId('continue-button').should('exist');

// Assert help and guidance link exists
cy.getByTestId('help-and-guidance-link').should('exist');
},
);
Expand Down Expand Up @@ -202,49 +195,67 @@ describe.skip('GP Workflow: Restore document version', () => {
});
});

context('Restore version uploading and completion', () => {
it(
'GP_ADMIN can successfully restore a previous version of a document',
{ tags: 'regression' },
() => {
beforeEachConfiguration(Roles.GP_ADMIN);
navigateToRestoreConfirm();
// Version 2 of the document
const versionToRestoreDocId = 'c889dbbf-2e3a-5860-ab90-9421b5e29b86';

// Intercept the upload session / document reference call
cy.intercept('POST', '/DocumentReference*', {
statusCode: 200,
body: {
const setupRestoreUploadIntercepts = () => {
// GET for the version being restored (different document ID to the active version)
cy.intercept('GET', `/DocumentReference/${versionToRestoreDocId}/_history/*`, {
statusCode: 200,
body: {
url: baseUrl + '/browserconfig.xml',
contentType: 'application/pdf',
},
}).as('getVersionDocument');

// PUT upload session - restore uses PUT not POST, keyed by clientId from request
cy.intercept('PUT', '/DocumentReference/*', (req) => {
const attachment = req.body.content[0].attachment;
req.reply({
statusCode: 200,
body: {
[attachment.clientId]: {
url: 'http://' + bucketUrlIdentifier,
fields: {
key: 'test-key',
key: '2a7a270e-aa1d-532e-8648-d5d8e3defb82',
'x-amz-algorithm': 'xxxx-xxxx-SHA256',
'x-amz-credential': 'xxxxxxxxxxx/20230904/eu-west-2/s3/aws4_request',
'x-amz-date': '20230904T125954Z',
'x-amz-security-token': 'xxxxxxxxx',
'x-amz-signature': '9xxxxxxxx',
},
},
}).as('uploadSession');
},
});
}).as('uploadSession');

// Intercept the S3 upload
cy.intercept('POST', '**' + bucketUrlIdentifier + '**', {
statusCode: 204,
}).as('s3Upload');
cy.intercept('POST', '**' + bucketUrlIdentifier + '**', {
statusCode: 204,
}).as('s3Upload');

// Intercept virus scan / document status polling
cy.intercept('GET', '/DocumentStatus*', {
statusCode: 200,
body: {
'2a7a270e-aa1d-532e-8648-d5d8e3defb82': {
status: 'succeeded',
},
},
}).as('documentStatus');
// Document status - key must match fields.key, status must be 'final'
cy.intercept('GET', '/DocumentStatus*', {
statusCode: 200,
body: {
'2a7a270e-aa1d-532e-8648-d5d8e3defb82': {
status: 'final',
},
},
}).as('documentStatus');

// Intercept the upload confirmation
cy.intercept('POST', '/UploadConfirm*', {
statusCode: 204,
}).as('uploadConfirm');
cy.intercept('POST', '/UploadConfirm*', {
statusCode: 204,
}).as('uploadConfirm');
};

context('Restore version uploading and completion', () => {
it(
'GP_ADMIN can successfully restore a previous version of a document',
{ tags: 'regression' },
() => {
beforeEachConfiguration(Roles.GP_ADMIN);
navigateToRestoreConfirm();
setupRestoreUploadIntercepts();

// Select "Yes" and continue
cy.getByTestId('yes-radio-btn').click();
Expand Down Expand Up @@ -274,39 +285,7 @@ describe.skip('GP Workflow: Restore document version', () => {
() => {
beforeEachConfiguration(Roles.GP_ADMIN);
navigateToRestoreConfirm();

// Set up intercepts for the upload flow
cy.intercept('POST', '/DocumentReference*', {
statusCode: 200,
body: {
url: 'http://' + bucketUrlIdentifier,
fields: {
key: 'test-key',
'x-amz-algorithm': 'xxxx-xxxx-SHA256',
'x-amz-credential': 'xxxxxxxxxxx/20230904/eu-west-2/s3/aws4_request',
'x-amz-date': '20230904T125954Z',
'x-amz-security-token': 'xxxxxxxxx',
'x-amz-signature': '9xxxxxxxx',
},
},
}).as('uploadSession');

cy.intercept('POST', '**' + bucketUrlIdentifier + '**', {
statusCode: 204,
}).as('s3Upload');

cy.intercept('GET', '/DocumentStatus*', {
statusCode: 200,
body: {
'2a7a270e-aa1d-532e-8648-d5d8e3defb82': {
status: 'succeeded',
},
},
}).as('documentStatus');

cy.intercept('POST', '/UploadConfirm*', {
statusCode: 204,
}).as('uploadConfirm');
setupRestoreUploadIntercepts();

// Complete the restore
cy.getByTestId('yes-radio-btn').click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
import { Roles } from '../../../support/roles';
import dbItem from '../../../fixtures/dynamo-db-items/active-patient-h81109.json';
import dbItem1 from '../../../fixtures/dynamo-db-items/restore-data/active-patient-h81109-v1.json';
import dbItem2 from '../../../fixtures/dynamo-db-items/restore-data/active-patient-h81109-v2.json';

const workspace = Cypress.env('WORKSPACE');
dbItem.FileLocation = dbItem.FileLocation.replace('{env}', workspace);
const activePatient = 9730154708; //9730154708,9730154376
dbItem1.FileLocation = dbItem1.FileLocation.replace('{env}', workspace);
dbItem2.FileLocation = dbItem2.FileLocation.replace('{env}', workspace);

const activePatient = '9730154708'; //9730154708,9730154376
const bucketName = `${workspace}-lloyd-george-store`;
const tableName = `${workspace}_LloydGeorgeReferenceMetadata`;
const fileName = `${activePatient}/e4a6d7f7-01f3-44be-8964-515b2c0ec180`;
const fileName = `${activePatient}/c165a49e-71b3-4662-8494-49c6b08070ba`;

const patientVerifyUrl = '/patient/verify';
const documentViewUrl = '/patient/documents';

// inital test works if you prepopulate the data need to sort out populating database
describe.skip('GP Workflow: restore version history', () => {
describe('GP Workflow: restore version history', () => {
context('Version history button is visible on document view page', () => {
beforeEach(() => {
cy.deleteFileFromS3(bucketName, fileName);
cy.deleteItemFromDynamoDb(tableName, dbItem.ID);
cy.addPdfFileToS3(bucketName, fileName, 'test_patient_record.pdf');
cy.addItemToDynamoDb(tableName, dbItem);
try {
cy.addPdfFileToS3(bucketName, fileName, 'lg-files/simple_pages/6.pdf').then(
(v1Response) => {
dbItem1.S3VersionID = v1Response.VersionId;
cy.addPdfFileToS3(bucketName, fileName, 'lg-files/simple_pages/7.pdf').then(
(v2Response) => {
dbItem2.S3VersionID = v2Response.VersionId;
cy.addItemToDynamoDb(tableName, dbItem1);
cy.addItemToDynamoDb(tableName, dbItem2);
},
);
},
);
} catch (error) {
cy.log('Error in beforeEach setup:', error);
}
});

afterEach(() => {
cy.deleteFileFromS3(bucketName, fileName);
cy.deleteItemFromDynamoDb(tableName, dbItem.ID);
cy.deleteItemFromDynamoDb(tableName, dbItem1.ID);
cy.deleteItemFromDynamoDb(tableName, dbItem2.ID);
});

it(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Author": "H81109",
"ContentType": "application/pdf",
"Created": "2023-12-05T16:06:48.300566Z",
"CurrentGpOds": "H81109",
"Custodian": "H81109",
"Deleted": "",
"DocStatus": "deprecated",
"DocumentScanCreation": "2023-01-01",
"DocumentSnomedCodeType": "16521000000101",
"FileLocation": "s3://{env}-lloyd-george-store/9730154708/c165a49e-71b3-4662-8494-49c6b08070ba",
"FileName": "1of1_Lloyd_George_Record_[Haley Glenda RUDKIN]_[9730154708]_[07-08-2023].pdf",
"FileSize": "192910",
"ID": "51ca569e-4a86-468a-9781-555da23b685f",
"LastUpdated": "1713800398",
"NhsNumber": "9730154708",
"S3FileKey": "9730154708/c165a49e-71b3-4662-8494-49c6b08070ba",
"S3VersionID": "_Ac549L3L0WbwLXwrIqtQ6ZsLVawWgaU",
"Status": "superseded",
"Uploaded": true,
"Uploading": false,
"Version": "1",
"VirusScannerResult": "Clean"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Author": "H81109",
"ContentType": "application/pdf",
"Created": "2023-12-05T16:06:48.300566Z",
"CurrentGpOds": "H81109",
"Custodian": "H81109",
"Deleted": "",
"DocStatus": "final",
"DocumentScanCreation": "2023-01-01",
"DocumentSnomedCodeType": "16521000000101",
"FileLocation": "s3://{env}-lloyd-george-store/9730154708/c165a49e-71b3-4662-8494-49c6b08070ba",
"FileName": "1of1_Lloyd_George_Record_[Haley Glenda RUDKIN]_[9730154708]_[07-08-2023].pdf",
"FileSize": "192910",
"ID": "0921822f-121b-5edf-9e13-3fbe1b9d4fad",
"LastUpdated": "1713800398",
"NhsNumber": "9730154708",
"S3FileKey": "9730154708/c165a49e-71b3-4662-8494-49c6b08070ba",
"S3VersionID": "_Ac549L3L0WbwLXwrIqtQ6ZsLVawWgaU",
"Status": "current",
"Uploaded": true,
"Uploading": false,
"Version": "2",
"VirusScannerResult": "Clean"
}
Loading