From 660e73acf845343626bedba0db3c38106513c6a2 Mon Sep 17 00:00:00 2001 From: Alok Date: Thu, 14 Nov 2024 23:46:45 +0530 Subject: [PATCH] Tests to verify error handling and access restrictions during facility creation --- .../e2e/facility_spec/FacilityCreation.cy.ts | 33 +++++++++++++++++++ .../pageobject/Facility/FacilityCreation.ts | 4 +++ 2 files changed, 37 insertions(+) diff --git a/cypress/e2e/facility_spec/FacilityCreation.cy.ts b/cypress/e2e/facility_spec/FacilityCreation.cy.ts index 5e644238999..1993b7717f9 100644 --- a/cypress/e2e/facility_spec/FacilityCreation.cy.ts +++ b/cypress/e2e/facility_spec/FacilityCreation.cy.ts @@ -59,6 +59,11 @@ describe("Facility Creation", () => { const triageErrorMessage = ["This field is required"]; const facilityType = "Primary Health Centres"; + const nonAdminUsers = [ + { username: "dummynurse1", password: "Coronasafe@123" }, + { username: "devdoctor", password: "Coronasafe@123" }, + ]; + before(() => { loginPage.loginAsDistrictAdmin(); cy.saveLocalStorage(); @@ -317,6 +322,34 @@ describe("Facility Creation", () => { ); }); + it("Should display error when district admin tries to create facility in a different district", () => { + facilityPage.visitCreateFacilityPage(); + facilityPage.fillFacilityName(facilityName); + facilityPage.selectFacilityType(facilityType); + facilityPage.fillPincode("682001"); + facilityPage.selectStateOnPincode("Kerala"); + facilityPage.selectDistrictOnPincode("Kottayam"); + facilityPage.selectLocalBody("Arpookara"); + facilityPage.selectWard("5"); + facilityPage.fillAddress(facilityAddress); + facilityPage.fillPhoneNumber(facilityNumber); + facilityPage.submitForm(); + facilityPage.verifyErrorNotification( + "You do not have permission to perform this action.", + ); + }); + + it("Access Restriction for Non-Admin Users to facility creation page", () => { + nonAdminUsers.forEach((user) => { + loginPage.login(user.username, user.password); + cy.visit("/facility/create"); + + facilityPage.verifyErrorNotification( + "You don't have permission to perform this action. Contact the admin", + ); + }); + }); + afterEach(() => { cy.saveLocalStorage(); }); diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index 6ce0cc6270e..80cf5e4a7be 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -302,6 +302,10 @@ class FacilityPage { cy.verifyNotification(message); } + verifyErrorNotification(message: string) { + cy.verifyNotification(message); + } + visitAlreadyCreatedFacility() { cy.intercept("GET", "**/api/v1/facility/**").as("getFacilities"); cy.get("[id='facility-details']").first().click();