Skip to content

Commit

Permalink
PRMDR 438/504 - E2E tests for RBAC and tidy (#164)
Browse files Browse the repository at this point in the history
* Cypress folder structure modified to make test structure clearer
* RBAC cypress tests added

---------

Co-authored-by: Scott Alexander <scott.alexander@madetech.com>
  • Loading branch information
SRAlexander and Scott Alexander authored Nov 27, 2023
1 parent 38c121e commit 667fc7c
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import authPayload from '../../fixtures/requests/auth/GET_TokenRequest_GP_ADMIN.json';
import authPayload from '../../../fixtures/requests/auth/GET_TokenRequest_GP_ADMIN.json';

describe('authentication & authorisation', () => {
const baseUrl = 'http://localhost:3000';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const patient = {
const smokeTest = Cypress.env('CYPRESS_RUN_AS_SMOKETEST') ?? false;
const baseUrl = Cypress.env('CYPRESS_BASE_URL') ?? 'http://localhost:3000/';

describe('assert GP_ADMIM workflow path', () => {
const baseUrl = 'http://localhost:3000';
const forbiddenRoutes = ['search/patient', 'search/patient/result', 'search/results'];

describe('assert GP_ADMIN user has access to the GP_ADMIM workflow path', () => {
context('session management', () => {
it('sets session storage on login and checks starting url route', () => {
if (!smokeTest) {
Expand All @@ -26,20 +26,32 @@ describe('assert GP_ADMIM workflow path', () => {
}

cy.login('GP_ADMIN');
cy.url().should('eq', baseUrl + '/search/upload');
cy.url().should('eq', baseUrl + 'search/upload');

cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(testPatient);
cy.get('#search-submit').click();
cy.wait('@search');

cy.url().should('include', 'upload');
cy.url().should('eq', baseUrl + '/search/upload/result');
cy.url().should('eq', baseUrl + 'search/upload/result');

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

cy.url().should('include', 'lloyd-george-record');
cy.url().should('eq', baseUrl + '/search/patient/lloyd-george-record');
cy.url().should('eq', baseUrl + 'search/patient/lloyd-george-record');
});
});
});

describe('assert GP ADMIM role cannot access expected forbidden routes', () => {
context('forbidden routes', () => {
forbiddenRoutes.forEach((forbiddenRoute) => {
it('assert GP Admin cannot access route ' + forbiddenRoute, () => {
cy.login('GP_ADMIN');
cy.visit(baseUrl + forbiddenRoute);
cy.url().should('include', 'unauthorised');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const patient = {
const smokeTest = Cypress.env('CYPRESS_RUN_AS_SMOKETEST') ?? false;
const baseUrl = Cypress.env('CYPRESS_BASE_URL') ?? 'http://localhost:3000/';

describe('assert GP_CLINICAL workflow path', () => {
const baseUrl = 'http://localhost:3000';
const forbiddenRoutes = ['search/patient', 'search/patient/result', 'search/results'];

describe('assert GP_CLINICAL user has access to the GP_CLINICAL workflow path', () => {
context('session management', () => {
it('sets session storage on login and checks starting url route', () => {
if (!smokeTest) {
Expand All @@ -26,20 +26,32 @@ describe('assert GP_CLINICAL workflow path', () => {
}

cy.login('GP_CLINICAL');
cy.url().should('eq', baseUrl + '/search/upload');
cy.url().should('eq', baseUrl + 'search/upload');

cy.get('#nhs-number-input').click();
cy.get('#nhs-number-input').type(testPatient);
cy.get('#search-submit').click();
cy.wait('@search');

cy.url().should('include', 'upload');
cy.url().should('eq', baseUrl + '/search/upload/result');
cy.url().should('eq', baseUrl + 'search/upload/result');

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

cy.url().should('include', 'lloyd-george-record');
cy.url().should('eq', baseUrl + '/search/patient/lloyd-george-record');
cy.url().should('eq', baseUrl + 'search/patient/lloyd-george-record');
});
});
});

describe('assert GP ADMIM role cannot access expected forbidden routes', () => {
context('forbidden routes', () => {
forbiddenRoutes.forEach((forbiddenRoute) => {
it('assert GP Admin cannot access route ' + forbiddenRoute, () => {
cy.login('GP_CLINICAL');
cy.visit(baseUrl + forbiddenRoute);
cy.url().should('include', 'unauthorised');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ const patient = {

const smokeTest = Cypress.env('CYPRESS_RUN_AS_SMOKETEST') ?? false;
const baseUrl = Cypress.env('CYPRESS_BASE_URL') ?? 'http://localhost:3000/';
const forbiddenRoutes = [
'search/patient/lloyd-george-record',
'search/upload',
'search/upload/result',
'upload/submit',
];

describe('assert PCSE workflow path', () => {
const baseUrl = 'http://localhost:3000';

describe('assert PCSE user has access to the PCSE workflow path ', () => {
context('session management', () => {
it('sets session storage on login and checks starting url route', () => {
if (!smokeTest) {
Expand All @@ -27,15 +31,27 @@ describe('assert PCSE workflow path', () => {

cy.login('PCSE');

cy.url().should('eq', baseUrl + '/search/patient');
cy.url().should('eq', baseUrl + 'search/patient');

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();
cy.url().should('eq', baseUrl + '/search/results');
cy.url().should('eq', baseUrl + 'search/results');
});
});
});

describe('assert PCSE role cannot access expected forbidden routes', () => {
context('forbidden routes', () => {
forbiddenRoutes.forEach((forbiddenRoute) => {
it('assert PCSE cannot access route ' + forbiddenRoute, () => {
cy.login('PCSE');
cy.visit(baseUrl + forbiddenRoute);
cy.url().should('include', 'unauthorised');
});
});
});
});
Loading

0 comments on commit 667fc7c

Please sign in to comment.