From c1318217a27e14d13b8b9a1b58dd8fbc7c40b1c2 Mon Sep 17 00:00:00 2001 From: oxdev03 <140103378+oxdev03@users.noreply.github.com> Date: Sun, 28 Apr 2024 15:32:43 +0200 Subject: [PATCH] chore: save user session --- .../cypress/e2e/1-user/03-admin.cy.ts | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/apps/dashboard/cypress/e2e/1-user/03-admin.cy.ts b/apps/dashboard/cypress/e2e/1-user/03-admin.cy.ts index 981e5f5..db7e818 100644 --- a/apps/dashboard/cypress/e2e/1-user/03-admin.cy.ts +++ b/apps/dashboard/cypress/e2e/1-user/03-admin.cy.ts @@ -25,44 +25,53 @@ describe("pm2.web user administration", () => { }; } - beforeEach(() => { + function insertUsers() { cy.task("clearDB"); for (let i = 0; i < userConfig.length; i++) { cy.task("createUser", getUser(i)); } - cy.visit("/"); - }); + } - it("it should have 3 users with name, email, role", () => { + context("User List", () => { const user = getUser(0); - cy.login(user.email, user.password); - cy.visit("/user"); - cy.get('[data-cy="user-item-email"]').should("have.length", userConfig.length); - for (let i = 0; i < userConfig.length; i++) { - const u = getUser(i); - const role = u.owner ? "OWNER" : u.admin ? "ADMIN" : "NONE"; + before(() => { + insertUsers(); + cy.login(user.email, user.password); + cy.visit("/user"); + }); - cy.get('[data-cy="user-item-email"]').contains(u.email); - cy.get('[data-cy="user-item-name"]').contains(u.name); - cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-select"]`).should( - `be.${u.admin || u.owner ? "disabled" : "enabled"}`, - ); - cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-role"]`).should("have.value", role); - } + it("it should have 3 users with name, email, role", () => { + for (let i = 0; i < userConfig.length; i++) { + const u = getUser(i); + const role = u.owner ? "OWNER" : u.admin ? "ADMIN" : "NONE"; + + cy.get('[data-cy="user-item-email"]').contains(u.email); + cy.get('[data-cy="user-item-name"]').contains(u.name); + cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-select"]`).should( + `be.${u.admin || u.owner ? "disabled" : "enabled"}`, + ); + cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-role"]`).should("have.value", role); + } + }); }); context("Delete User with OWNER Permission", () => { const user = getUser(0); beforeEach(() => { - //cy.session("Session", () => { - cy.login(user.email, user.password); - //}); + cy.session("Session", () => { + insertUsers(); + cy.login(user.email, user.password); + }); cy.visit("/user"); }); + after(() => { + Cypress.session.clearAllSavedSessions(); + }); + it("it should delete user", () => { const u = getUser(2); cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-delete"]`).click(); @@ -79,5 +88,20 @@ describe("pm2.web user administration", () => { cy.get(`.mantine-Notifications-root`).children().contains(`Failed to delete user: ${user.name}`); cy.get(`.mantine-Notifications-root`).children().contains(`Owner cannot be deleted`); }); + + it("should have at least one owner", () => { + cy.get(`[data-cy-id="${user.email}"] * > [data-cy="user-item-role"]`).select("ADMIN"); + // should show notification + cy.get(`.mantine-Notifications-root`).children().contains(`Failed to update role to Admin`); + cy.get(`.mantine-Notifications-root`).children().contains(`Their needs to be at least one owner.`); + }); + + it("should be possible to update role to OWNER", () => { + const u = getUser(1); + cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-role"]`).select("OWNER"); + // should show notification + cy.get(`.mantine-Notifications-root`).children().contains(`Updated role to Owner`); + cy.get(`.mantine-Notifications-root`).children().contains(`Updated role successfully`); + }); }); });