Skip to content

Commit

Permalink
chore: save user session
Browse files Browse the repository at this point in the history
  • Loading branch information
oxdev03 committed Apr 28, 2024
1 parent 28f1d5a commit c131821
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions apps/dashboard/cypress/e2e/1-user/03-admin.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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`);
});
});
});

0 comments on commit c131821

Please sign in to comment.