Skip to content

Commit

Permalink
PRMDR-722: Add feature flags e2e tests for ARF and LG workflows (#311)
Browse files Browse the repository at this point in the history
* [PRMDR-722] add upload feature flags e2e tests

* [PRMDR-722] add intercept in case default flag settings change in future

* Add feature flags e2e tests for ARF and LG workflows

* pr changes

---------

Co-authored-by: RachelHowellNHS <rachel.howell6@nhs.net>
  • Loading branch information
abbas-khan10 and RachelHowellNHS authored Mar 1, 2024
1 parent 427dabc commit e7adc49
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Roles, roleName } from '../../../support/roles';

const baseUrl = Cypress.config('baseUrl');
const searchPatientUrl = '/search/patient';

const testPatient = '9000000009';
const patient = {
birthDate: '1970-01-01',
familyName: 'Default Surname',
givenName: ['Default Given Name'],
nhsNumber: testPatient,
postalCode: 'AA1 1AA',
superseded: false,
restricted: false,
active: false,
};

const navigateToUploadPage = () => {
cy.intercept('GET', '/SearchPatient*', {
statusCode: 200,
body: patient,
}).as('search');

cy.visit(searchPatientUrl);
cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(testPatient);

cy.get('#search-submit').click();
cy.wait('@search');

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

const gpRoles = [Roles.GP_ADMIN, Roles.GP_CLINICAL];

describe('Feature flags - ARF Workflow', () => {
gpRoles.forEach((role) => {
context(`As a ${roleName(role)} user visiting the ARF page for an inactive patient`, () => {
it(
'displays the page when both feature flags are enabled',
{ tags: 'regression' },
() => {
cy.login(role);
navigateToUploadPage();

cy.url().should('eq', baseUrl + '/patient/upload');
cy.get('h1').should('not.have.text', 'Unauthorised access');
},
);

it(
'displays the unauthorised page when ARF workflow feature flag is disabled',
{ tags: 'regression' },
() => {
const featureFlags = {
uploadArfWorkflowEnabled: false,
uploadLambdaEnabled: true,
};
cy.login(role, true, featureFlags);
navigateToUploadPage();

cy.url().should('eq', baseUrl + '/unauthorised');
cy.get('h1').should('have.text', 'Unauthorised access');
},
);

it(
'displays the unauthorised page when upload lambda feature flag is disabled',
{ tags: 'regression' },
() => {
const featureFlags = {
uploadArfWorkflowEnabled: true,
uploadLambdaEnabled: false,
};

cy.login(role, true, featureFlags);
navigateToUploadPage();

cy.url().should('eq', baseUrl + '/unauthorised');
cy.get('h1').should('have.text', 'Unauthorised access');
},
);

it(
'displays the unauthorised page when both upload and ARF workflow feature flag are disabled',
{ tags: 'regression' },
() => {
const featureFlags = {
uploadArfWorkflowEnabled: false,
uploadLambdaEnabled: false,
};

cy.login(role, true, featureFlags);
navigateToUploadPage();

cy.url().should('eq', baseUrl + '/unauthorised');
cy.get('h1').should('have.text', 'Unauthorised access');
},
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Roles } from '../../../support/roles';
import searchPatientPayload from '../../../fixtures/requests/GET_SearchPatient.json';

const beforeEachConfiguration = (role, featureFlags) => {
cy.login(role, true, featureFlags);
cy.intercept('GET', '/SearchPatient*', {
statusCode: 200,
body: searchPatientPayload,
}).as('search');
cy.getByTestId('nhs-number-input').type(searchPatientPayload.nhsNumber);
cy.getByTestId('search-submit-btn').click();
cy.wait('@search');
};

describe('Feature flags - Lloyd George Workflow', () => {
context('As a GP admin BSOL user visiting Lloyd George record page', () => {
it(
'displays upload text and button when both upload feature flags are enabled',
{ tags: 'regression' },
() => {
const featureFlags = {
uploadLloydGeorgeWorkflowEnabled: true,
uploadLambdaEnabled: true,
};
beforeEachConfiguration(Roles.GP_ADMIN, featureFlags);
cy.intercept('GET', '/LloydGeorgeStitch*', {
statusCode: 404,
});
cy.get('#verify-submit').click();

cy.getByTestId('upload-patient-record-text').should('exist');
cy.getByTestId('upload-patient-record-button').should('exist');
},
);

it(
'does not display upload text and button when neither upload feature flags are enabled',
{ tags: 'regression' },
() => {
const featureFlags = {
uploadLloydGeorgeWorkflowEnabled: false,
uploadLambdaEnabled: false,
};
beforeEachConfiguration(Roles.GP_ADMIN, featureFlags);
cy.intercept('GET', '/LloydGeorgeStitch*', {
statusCode: 404,
});
cy.get('#verify-submit').click();

cy.getByTestId('upload-patient-record-text').should('not.exist');
cy.getByTestId('upload-patient-record-button').should('not.exist');
},
);

it(
'does not display upload text and button when upload lambda feature flag is not enabled',
{ tags: 'regression' },
() => {
const featureFlags = {
uploadLloydGeorgeWorkflowEnabled: true,
uploadLambdaEnabled: false,
};
beforeEachConfiguration(Roles.GP_ADMIN, featureFlags);
cy.intercept('GET', '/LloydGeorgeStitch*', {
statusCode: 404,
});
cy.get('#verify-submit').click();

cy.getByTestId('upload-patient-record-text').should('not.exist');
cy.getByTestId('upload-patient-record-button').should('not.exist');
},
);

it(
'does not display upload text and button when upload Lloyd George feature flag is not enabled',
{ tags: 'regression' },
() => {
const featureFlags = {
uploadLloydGeorgeWorkflowEnabled: false,
uploadLambdaEnabled: true,
};
beforeEachConfiguration(Roles.GP_ADMIN, featureFlags);
cy.intercept('GET', '/LloydGeorgeStitch*', {
statusCode: 404,
});
cy.get('#verify-submit').click();

cy.getByTestId('upload-patient-record-text').should('not.exist');
cy.getByTestId('upload-patient-record-button').should('not.exist');
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ const stubbedResponseMulti = {
};
describe('GP Workflow: Upload Lloyd George record when user is GP admin BSOL and patient has no record', () => {
const beforeEachConfiguration = () => {
cy.intercept('GET', '/FeatureFlags*', {
statusCode: 200,
body: {
uploadLloydGeorgeWorkflowEnabled: true,
uploadLambdaEnabled: true,
},
});
cy.login(Roles.GP_ADMIN);
cy.visit(searchPatientUrl);

Expand Down
19 changes: 17 additions & 2 deletions app/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DynamoDB, S3 } from 'aws-sdk';
import { Roles, roleIds, roleList } from './roles';
import { defaultFeatureFlags, FeatureFlags } from './feature_flags';
import Bluebird from 'cypress/types/bluebird';
import './aws.commands';

Expand All @@ -11,7 +12,7 @@ Cypress.Commands.add('getByTestId', (selector, ...args) => {
return cy.get(`[data-testid=${selector}]`, ...args);
});

Cypress.Commands.add('login', (role, isBSOL = true) => {
Cypress.Commands.add('login', (role, isBSOL = true, featureFlags) => {
if (roleIds.includes(role)) {
const roleName = roleList.find((roleName) => Roles[roleName] === role);
// Login for regression tests
Expand All @@ -25,6 +26,19 @@ Cypress.Commands.add('login', (role, isBSOL = true) => {
statusCode: 200,
fixture: fixturePath,
}).as('auth');

if (featureFlags) {
cy.intercept('GET', '/FeatureFlags*', {
statusCode: 200,
body: featureFlags,
}).as('featureFlags');
} else {
cy.intercept('GET', '/FeatureFlags*', {
statusCode: 200,
body: defaultFeatureFlags,
}).as('featureFlags');
}

cy.visit(authCallback);
cy.wait('@auth');
} else {
Expand Down Expand Up @@ -113,8 +127,9 @@ declare global {
* Mock user login by intercepting the {baseUrl}/auth-callback request
* @param {Roles} role - The user role to login with. Must be an enum of Roles
* @param {boolean} isBSOL - Whether the user GP is located in BSOL area
* @param featureFlags - Feature flags values to override the defaults
*/
login(role: Roles, isBSOL?: boolean): Chainable<void>;
login(role: Roles, isBSOL?: boolean, featureFlags?: FeatureFlags): Chainable<void>;

/**
* Real user login via CIS2 and redirect back to {baseUrl}/auth-callback.
Expand Down
9 changes: 9 additions & 0 deletions app/cypress/support/feature_flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type FeatureFlags = {
[key: string]: boolean;
};

export const defaultFeatureFlags: FeatureFlags = {
uploadLloydGeorgeWorkflowEnabled: true,
uploadArfWorkflowEnabled: true,
uploadLambdaEnabled: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function LloydGeorgeRecordError({ downloadStage, setStage }: Props) {
{featureFlags.uploadLloydGeorgeWorkflowEnabled &&
featureFlags.uploadLambdaEnabled && (
<>
<p>
<p data-testid="upload-patient-record-text">
You can upload full or part of a patient record. You can upload
supporting files once the record is uploaded.
</p>
Expand Down

0 comments on commit e7adc49

Please sign in to comment.