Skip to content

Commit

Permalink
Add intercept and wait on admin endpoint calls for AB#16782 (#6251)
Browse files Browse the repository at this point in the history
* Add intercept and wait on admin endpoint calls for AB#16782

* Code review change for AB#16782
  • Loading branch information
BrianMaki authored Jul 5, 2024
1 parent fb90729 commit c07b909
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { removeUserIfExists } from "../../utilities/kcUtilities";

const username = Cypress.env("idir_username");
const password = Cypress.env("idir_password");
const user = "FncTstUser1";
const timeout = 45000;
const defaultTimeout = 60000;

describe("Provision", () => {
beforeEach(() => {
Expand All @@ -29,7 +27,10 @@ describe("Provision", () => {
cy.get("[data-testid=roles-select]").click();
cy.get("[data-testid=role]").contains("AdminUser").click();
cy.get("[data-testid=save-btn]").parent().parent().click(0, 0);

cy.intercept("POST", "**/AgentAccess/").as("postAgentAccess");
cy.get("[data-testid=save-btn]").click();
cy.wait("@postAgentAccess", { timeout: defaultTimeout });
cy.get("[data-testid=provision-dialog-modal-text]").should("not.exist");

cy.log("Validate user was created.");
Expand Down Expand Up @@ -59,8 +60,10 @@ describe("Provision", () => {
cy.get("[data-testid=identity-provider]").contains("IDIR").click();
cy.get("[data-testid=roles-select]").click();
cy.get("[data-testid=role]").contains("AdminUser").click();
cy.intercept("POST", "**/AgentAccess/").as("postAgentAccess");
cy.get("[data-testid=save-btn]").parent().parent().click(0, 0);
cy.get("[data-testid=save-btn]").click();
cy.wait("@postAgentAccess", { timeout: defaultTimeout });

cy.log("Validate duplicate user error.");
cy.get("[data-testid=add-error-alert]").should("exist");
Expand All @@ -72,7 +75,7 @@ describe("Provision", () => {
cy.intercept("GET", `**/AgentAccess/?query=${user}`).as("getUser");
cy.get("[data-testid=query-input]").clear().type(user);
cy.get("[data-testid=search-btn]").click();
cy.wait("@getUser", { timeout });
cy.wait("@getUser", { timeout: defaultTimeout });
cy.get("[data-testid^=agent-table-username-]")
.contains(user.toLowerCase())
.parents(".mud-table-row")
Expand All @@ -93,8 +96,10 @@ describe("Provision", () => {
// This line may trigger ResizeObserver exception
cy.get("[data-testid=role]").contains("AdminAnalyst").click();

cy.intercept("PUT", "**/AgentAccess/").as("putAgentAccess");
cy.get("[data-testid=save-btn]").parent().parent().click(0, 0);
cy.get("[data-testid=save-btn]").click();
cy.wait("@putAgentAccess", { timeout: defaultTimeout });
cy.get("[data-testid=provision-dialog-modal-text]").should("not.exist");

cy.log("Validate user edit.");
Expand All @@ -115,15 +120,19 @@ describe("Provision", () => {
});

it("Delete User", () => {
cy.intercept("GET", `**/AgentAccess/?query=${user}`).as("getUser");
cy.get("[data-testid=query-input]").clear().type(user);
cy.get("[data-testid=search-btn]").click();
cy.wait("@getUser", { timeout: defaultTimeout });
cy.get("[data-testid^=agent-table-username-]")
.contains(user.toLowerCase())
.parents(".mud-table-row")
.get("[data-testid^=agent-table-delete-btn]")
.click();
cy.get("[data-testid=confirm-delete-message]").should("be.visible");
cy.intercept("DELETE", "**/AgentAccess/?id=*").as("deleteAgentAccess");
cy.get("[data-testid=confirm-delete-btn]").click();
cy.wait("@deleteAgentAccess", { timeout: defaultTimeout });
cy.get("[data-testid=confirm-delete-message]").should("not.exist");

cy.log("Validate user delete.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ const existingEmail = "somebody@healthgateway.gov.bc.ca";
const validEmail = "nobody@healthgateway.gov.bc.ca";
const notFoundEmail = "nobody@salesforce.gov.bc.ca";
const invalidEmail = "nobody@";
const defaultTimeout = 60000;

function setupGetUserAccessAlias() {
cy.intercept("GET", "**/BetaFeature/UserAccess*").as("getUserAccess");
}

function setupPutUserAccessAlias() {
cy.intercept("PUT", "**/UserAccess").as("putUserAccess");
}

function waitForGetUserAccess() {
cy.wait("@getUserAccess", { timeout: defaultTimeout });
}

function waitForPutUserAccess() {
cy.wait("@putUserAccess", { timeout: defaultTimeout });
}

describe("Beta feature access", () => {
beforeEach(() => {
Expand Down Expand Up @@ -48,8 +65,11 @@ describe("Beta feature access", () => {
.should("be.enabled")
.clear()
.type(notFoundEmail);

cy.get(".d-flex").contains("Invalid email format").should("not.exist");
setupGetUserAccessAlias();
cy.get("[data-testid=search-button]").click();
waitForGetUserAccess();

cy.get("[data-testid=get-user-access-error-message]").should(
"be.visible"
Expand All @@ -62,13 +82,17 @@ describe("Beta feature access", () => {
// Tab to Search and search with a valid email
cy.log("Verify search with valid email.");
selectTab("[data-testid=beta-access-tabs]", "Search");
setupGetUserAccessAlias();

cy.get("[data-testid=query-input]")
.should("be.visible")
.should("be.enabled")
.clear()
.type(validEmail);

cy.get(".d-flex").contains("Invalid email format").should("not.exist");
cy.get("[data-testid=search-button]").click();
waitForGetUserAccess();

cy.get("[data-testid=get-user-access-error-message]").should(
"not.exist"
Expand All @@ -80,7 +104,9 @@ describe("Beta feature access", () => {

// Assign salesforce feature
cy.log("Verify assign salesforce feature on Search.");
setupPutUserAccessAlias();
cy.get("[data-testid=salesforce-access-switch]").click();
waitForPutUserAccess();
cy.get("[data-testid=salesforce-access-switch]").should("be.checked");

// Tab to View and verify assigned feature(s)
Expand Down Expand Up @@ -132,7 +158,9 @@ describe("Beta feature access", () => {

// Assign salesforce feature again on Search
cy.log("Verify re-assign salesforce feature access on Search tab.");
setupPutUserAccessAlias();
cy.get("[data-testid=salesforce-access-switch]").click();
waitForPutUserAccess();
cy.get("[data-testid=salesforce-access-switch]").should("be.checked");

// Tab back to View and verify salesforce is assigned
Expand All @@ -155,7 +183,9 @@ describe("Beta feature access", () => {

// Un-assign salesforce on Search
cy.log("Verify un-assign salesforce feature on Search tab.");
setupPutUserAccessAlias();
cy.get("[data-testid=salesforce-access-switch]").click();
waitForPutUserAccess();
cy.get("[data-testid=salesforce-access-switch]").should(
"not.be.checked"
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getTodayPlusDaysDate } from "../../utilities/sharedUtilities";

const defaultTimeout = 60000;

describe("Communications", () => {
beforeEach(() => {
cy.login(
Expand All @@ -26,7 +28,10 @@ describe("Communications", () => {
.clear()
.focus()
.type("Test Notification Content");

cy.intercept("POST", "**/Broadcast/").as("postBroadcast");
cy.get("[data-testid=save-btn]").click();
cy.wait("@postBroadcast", { timeout: defaultTimeout });
cy.get("[data-testid=broadcast-dialog-modal-text]").should("not.exist");

cy.log("Validate notification was created.");
Expand Down Expand Up @@ -86,7 +91,9 @@ describe("Communications", () => {
.focus()
.type("https://www.healthgateway.gov.bc.ca");

cy.intercept("PUT", "**/Broadcast/").as("putBroadcast");
cy.get("[data-testid=save-btn]").click();
cy.wait("@putBroadcast", { timeout: defaultTimeout });
cy.get("[data-testid=broadcast-dialog-modal-text]").should("not.exist");

cy.log("Validate notification was edited.");
Expand All @@ -111,12 +118,13 @@ describe("Communications", () => {
});

cy.get("[data-testid=confirm-delete-message]").should("be.visible");
cy.intercept("DELETE", "**/Broadcast/").as("deleteBroadcast");
cy.get("[data-testid=confirm-delete-btn]").click();
cy.wait("@deleteBroadcast", { timeout: defaultTimeout });
cy.get("[data-testid=confirm-delete-message]").should("not.exist");

cy.log("Validate notification was deleted.");

cy.validateTableLoad("[data-testid=broadcast-table]");
cy.get(rowSelector)
.first()
.within(() => {
Expand Down Expand Up @@ -191,7 +199,10 @@ describe("Communications", () => {
.focus()
.type("Edited Mobile Comm");
});

cy.intercept("PUT", "**/Communication/").as("putCommunication");
cy.get("[data-testid=save-btn]").click();
cy.wait("@putCommunication", { timeout: defaultTimeout });
cy.get("[data-testid=comm-table-subject]").contains(
"Edited Mobile Comm"
);
Expand All @@ -205,7 +216,11 @@ describe("Communications", () => {
cy.get("[data-testid=confirm-cancel-btn]").click();
cy.get("[data-testid=confirm-delete-message]").should("not.exist");
cy.get("[data-testid=comm-table-delete-btn]").click();

cy.intercept("DELETE", "**/Communication/").as("deleteCommunication");
cy.get("[data-testid=confirm-delete-btn]").click();
cy.wait("@deleteCommunication", { timeout: defaultTimeout });

cy.get("[data-testid=confirm-delete-message]").should("not.exist");
cy.get("[data-testid=comm-table-subject]").should("not.exist");

Expand All @@ -227,7 +242,10 @@ describe("Communications", () => {
cy.get("[data-testid=status-type]")
.contains("Publish")
.click({ force: true });

cy.intercept("POST", "**/Communication/").as("postCommunication");
cy.get("[data-testid=save-btn]").click({ force: true });
cy.wait("@postCommunication", { timeout: defaultTimeout });
cy.get("[data-testid=comm-table-subject]").contains("New Mobile Comm");

cy.log("Validate add communication finished.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ const dependentToProtect = "9872868095"; // Jeffrey Lawrence Stallings
const guardianToAdd = "9735352488"; // Turpentine Garlandry
const guardianNotFound = "9735352489";
const guardianAlreadyAdded = "9735353315"; // BONNET PROTERVITY
const defaultTimeout = 60000;

function performSearch(phn) {
cy.intercept("GET", "**/Delegation/").as("getDelegation");
cy.get("[data-testid=query-input]").clear().type(phn);
cy.get("[data-testid=search-button]").click();
cy.wait("@getDelegation", { timeout: defaultTimeout });
}

function getTableRows(tableSelector) {
Expand All @@ -27,10 +30,7 @@ describe("Delegation Search", () => {
});

it("Verify response when searching for dependent without delegate.", () => {
cy.get("[data-testid=query-input]")
.clear()
.type(dependentWithoutGuardian.phn);
cy.get("[data-testid=search-button]").click();
performSearch(dependentWithoutGuardian.phn);

getTableRows("[data-testid=dependent-table]")
.should("have.length", 1)
Expand Down Expand Up @@ -90,8 +90,7 @@ describe("Delegation Search", () => {
});

it("Verify response contains dependent audit in descending datetime order as per seeded data.", () => {
cy.get("[data-testid=query-input]").clear().type(dependentWithAudit);
cy.get("[data-testid=search-button]").click();
performSearch(dependentWithAudit);

// Click delegation change header to show dependent audit
cy.get("[data-testid=delegation-changes-header")
Expand Down Expand Up @@ -161,10 +160,7 @@ describe("Delegation Protect", () => {
});

it("Verify protect dependent toggle and delegation cancel.", () => {
cy.get("[data-testid=query-input]")
.clear()
.type(dependentWithGuardian.phn);
cy.get("[data-testid=search-button]").click();
performSearch(dependentWithGuardian.phn);

// Protect dependent toggle
cy.get("[data-testid=dependent-protected-switch]").should(
Expand Down Expand Up @@ -219,8 +215,7 @@ describe("Delegation Protect", () => {
});

it("Verify add delegate dialog guardian not found and guardian already added.", () => {
cy.get("[data-testid=query-input]").clear().type(dependentWithAudit);
cy.get("[data-testid=search-button]").click();
performSearch(dependentWithAudit);

// Protect dependent toggle
cy.get("[data-testid=dependent-protected-switch]").should("be.checked");
Expand All @@ -229,12 +224,14 @@ describe("Delegation Protect", () => {
cy.get("[data-testid=add-button]").click();

// Delegate modal - phn not found
cy.intercept("GET", "**/Delegation/Delegate").as("getDelegate");
cy.get("[data-testid=delegate-phn-input]")
.clear()
.type(guardianNotFound);
cy.get("[data-testid=communication-dialog-modal-text]").within(() => {
cy.get("[data-testid=search-button]").click();
});
cy.wait("@getDelegate", { timeout: defaultTimeout });
cy.get("[data-testid=delegate-search-error-message]").should(
"be.visible"
);
Expand Down Expand Up @@ -262,8 +259,7 @@ describe("Delegation Protect", () => {
});

it("Verify protect/unprotect dependent toggle, add delegate, remove delegate, delegation save and delegation confirmation.", () => {
cy.get("[data-testid=query-input]").clear().type(dependentToProtect);
cy.get("[data-testid=search-button]").click();
performSearch(dependentToProtect);

// Confirm delegate table
getTableRows("[data-testid=delegate-table]").should("have.length", 2);
Expand All @@ -274,6 +270,9 @@ describe("Delegation Protect", () => {
);

// Protect
cy.intercept("PUT", "**/Delegation/*/ProtectDependent").as(
"protectDependent"
);
cy.get("[data-testid=dependent-protected-switch]").click();
cy.get("[data-testid=dependent-protected-switch]").should("be.checked");

Expand All @@ -283,15 +282,18 @@ describe("Delegation Protect", () => {
// Delegation Confirmation button
cy.get("[data-testid=audit-reason-input]").type("test");
cy.get("[data-testid=audit-confirm-button]").click({ force: true });
cy.wait("@protectDependent", { timeout: defaultTimeout });

// Add guardian
cy.get("[data-testid=add-button]").click();

// Delegate dialog - search with valid phn
cy.intercept("GET", "**/Delegation/Delegate").as("getDelegate");
cy.get("[data-testid=delegate-phn-input]").clear().type(guardianToAdd);
cy.get("[data-testid=communication-dialog-modal-text]").within(() => {
cy.get("[data-testid=search-button]").click();
});
cy.wait("@getDelegate", { timeout: defaultTimeout });
cy.get("[data-testid=delegate-search-error-message]").should(
"not.exist"
);
Expand All @@ -305,6 +307,7 @@ describe("Delegation Protect", () => {
// Delegation Confirmation button
cy.get("[data-testid=audit-reason-input]").type("test");
cy.get("[data-testid=audit-confirm-button]").click({ force: true });
cy.wait("@protectDependent", { timeout: defaultTimeout });

// Confirm guardian has been added to delegate table
getTableRows("[data-testid=delegate-table]").should("have.length", 3);
Expand Down Expand Up @@ -335,11 +338,15 @@ describe("Delegation Protect", () => {
getTableRows("[data-testid=delegate-table]").should("have.length", 2);

// Unprotect
cy.intercept("PUT", "**/Delegation/*/UnprotectDependent").as(
"unprotectDependent"
);
cy.get("[data-testid=dependent-protected-switch]").click();

// Confirmation button
cy.get("[data-testid=audit-reason-input]").type("test");
cy.get("[data-testid=audit-confirm-button]").click({ force: true });
cy.wait("@unprotectDependent", { timeout: defaultTimeout });

// Protect dependent toggle
cy.get("[data-testid=dependent-protected-switch]").should(
Expand Down
Loading

0 comments on commit c07b909

Please sign in to comment.