Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
import { expect, test } from "@playwright/test";
import { prisma } from "@rallly/database";
import { deleteAllMessages } from "@rallly/test-helpers";
import { createUserInDb, loginWithEmail } from "./test-utils";
const CONTROL_PANEL_NON_ADMIN_EMAIL = "[email protected]";
const CONTROL_PANEL_ADMIN_EMAIL = "[email protected]";
test.describe
.serial("Control Panel Access (/control-panel)", () => {
test.beforeEach(async () => {
await prisma.user.deleteMany({
where: {
email: {
in: [CONTROL_PANEL_NON_ADMIN_EMAIL, CONTROL_PANEL_ADMIN_EMAIL],
},
},
});
await deleteAllMessages();
});
test("should redirect unauthenticated user to login page", async ({
page,
}) => {
await page.goto("/control-panel");
await expect(page).toHaveURL("/login?redirectTo=%2Fcontrol-panel");
});
test("should explain missing admin access to a non-admin user", async ({
page,
}) => {
await createUserInDb({
email: CONTROL_PANEL_NON_ADMIN_EMAIL,
name: "Control Panel Non-Admin",
role: "user", // Explicitly 'user' role
});
await loginWithEmail(page, { email: CONTROL_PANEL_NON_ADMIN_EMAIL });
await page.goto("/control-panel");
await expect(page).toHaveURL(/.*\/admin-setup/);
await expect(
page.getByText("Administrator access required"),
).toBeVisible();
});
test("should allow an admin user to access the control panel", async ({
page,
}) => {
await createUserInDb({
email: CONTROL_PANEL_ADMIN_EMAIL,
name: "Control Panel Admin",
role: "admin",
});
await loginWithEmail(page, { email: CONTROL_PANEL_ADMIN_EMAIL });
await page.goto("/control-panel");
await expect(page).toHaveURL("/control-panel");
await expect(page.getByRole("heading", { name: "Home" })).toBeVisible();
});
});