Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 83 additions & 21 deletions apps/dashboard/cypress/e2e/1-user/03-admin.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,45 @@ 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("/");
}

beforeEach(() => {
insertUsers();
});

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";

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);
}
beforeEach(() => {
cy.login(user.email, user.password);
cy.visit("/user");
});

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", () => {
context("Actions with OWNER Permission", () => {
const user = getUser(0);

beforeEach(() => {
//cy.session("Session", () => {
cy.login(user.email, user.password);
//});

cy.visit("/user");
});

Expand All @@ -79,5 +83,63 @@ 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`);
});
});

context("Actions with ADMIN Permission", () => {
const user = getUser(1);

beforeEach(() => {
cy.login(user.email, user.password);
cy.visit("/user");
});

it("it should delete user", () => {
const u = getUser(2);
cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-delete"]`).click();
cy.get(`[data-cy-id="${u.email}"]`).should("not.exist");
// should show notification
cy.get(`.mantine-Notifications-root`).children().contains(`Deleted User: ${u.name}`);
cy.get(`.mantine-Notifications-root`).children().contains(`User deleted successfully`);
});

it("should not be able to delete owner", () => {
const u = getUser(0);
cy.get(`[data-cy-id="${u.email}"] * > [data-cy="user-item-delete"]`).click();
cy.get(`[data-cy-id="${u.email}"]`).should("exist");
// should show notification
cy.get(`.mantine-Notifications-root`).children().contains(`Failed to delete user: ${u.name}`);
cy.get(`.mantine-Notifications-root`).children().contains(`Owner cannot be deleted`);
});

it("should not 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(`Failed to update role to Owner`);
cy.get(`.mantine-Notifications-root`).children().contains(`Insufficient permission to change role to OWNER`);
});

it("should not be possible to update role of a OWNER", () => {
const u = getUser(0);
cy.get(`[data-cy-id="${u.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(`Insufficient permission to change role of owner`);
});
});
});
4 changes: 2 additions & 2 deletions apps/dashboard/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import "./commands";

Cypress.Commands.add("login", (email: string, password: string) => {
cy.visit("/login");
cy.get(`input[name="email"]`).type(email);
cy.get(`input[name="password"]`).type(password);
cy.get(`input[name="email"]`).type(email, { delay: 0 });
cy.get(`input[name="password"]`).type(password, { delay: 0 });
cy.get("form").submit();
cy.url().should("eq", "http://localhost:3000/");
});
28 changes: 14 additions & 14 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
"format:check": "prettier --check ."
},
"dependencies": {
"@mantine/charts": "^7.8.0",
"@mantine/code-highlight": "^7.8.0",
"@mantine/core": "^7.8.0",
"@mantine/form": "^7.8.0",
"@mantine/hooks": "^7.8.0",
"@mantine/notifications": "^7.8.0",
"@mantine/charts": "^7.9.1",
"@mantine/code-highlight": "^7.9.1",
"@mantine/core": "^7.9.1",
"@mantine/form": "^7.9.1",
"@mantine/hooks": "^7.9.1",
"@mantine/notifications": "^7.9.1",
"@pm2.web/mongoose-models": "*",
"@pm2.web/typings": "*",
"@tabler/icons-react": "^3.2.0",
"@tanstack/react-query": "^5.29.2",
"@tabler/icons-react": "^3.3.0",
"@tanstack/react-query": "^5.35.5",
"@trpc/client": "^11.0.0-rc.329",
"@trpc/next": "^11.0.0-rc.329",
"@trpc/react-query": "^11.0.0-rc.329",
Expand All @@ -47,14 +47,14 @@
"dotenv": "^16.4.5",
"dotenv-cli": "^7.4.1",
"lodash": "^4.17.21",
"mongodb-memory-server": "^9.1.8",
"next": "^14.2.2",
"mongodb-memory-server": "^9.2.0",
"next": "^14.2.3",
"next-auth": "^4.24.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"recharts": "^2.12.6",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"recharts": "^2.12.7",
"superjson": "^2.2.1",
"zod": "^3.22.5"
"zod": "^3.23.8"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
Expand Down
Loading