Skip to content

Commit 26b2972

Browse files
committed
tests, glorious tests
1 parent b2a8828 commit 26b2972

File tree

1 file changed

+125
-25
lines changed

1 file changed

+125
-25
lines changed

site/e2e/tests/roles.spec.ts

Lines changed: 125 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,157 @@
1-
import { expect, test } from "@playwright/test";
1+
import { type Page, expect, test } from "@playwright/test";
22
import { license, users } from "../constants";
3-
import { login } from "../helpers";
3+
import { login, requiresLicense } from "../helpers";
44
import { beforeCoderTest } from "../hooks";
5+
import {
6+
createOrganization,
7+
createOrganizationMember,
8+
setupApiCalls,
9+
} from "../api";
510

611
test.beforeEach(async ({ page }) => {
712
beforeCoderTest(page);
813
});
914

10-
test.describe("deployment settings access", () => {
11-
test("member cannot see deployment settings", async ({ page }) => {
15+
type AdminSetting = (typeof adminSettings)[number];
16+
17+
const adminSettings = [
18+
"Deployment",
19+
"Organizations",
20+
"Healthcheck",
21+
"Audit Logs",
22+
] as const;
23+
24+
async function hasAccessToAdminSettings(page: Page, settings: AdminSetting[]) {
25+
// Organizations and Audit Logs both require a license to be visible
26+
const visibleSettings = settings.filter(
27+
(it) => Boolean(license) || (it !== "Organizations" && it !== "Audit Logs"),
28+
);
29+
const adminSettingsButton = page.getByRole("button", {
30+
name: "Admin settings",
31+
});
32+
if (visibleSettings.length < 1) {
33+
await expect(adminSettingsButton).not.toBeVisible();
34+
return;
35+
}
36+
37+
await adminSettingsButton.click();
38+
39+
for (const name of visibleSettings) {
40+
await expect(page.getByText(name, { exact: true })).toBeVisible();
41+
}
42+
43+
const hiddenSettings = adminSettings.filter(
44+
(it) => !visibleSettings.includes(it),
45+
);
46+
for (const name of hiddenSettings) {
47+
await expect(page.getByText(name, { exact: true })).not.toBeVisible();
48+
}
49+
}
50+
51+
test.describe("roles admin settings access", () => {
52+
test("member cannot see admin settings", async ({ page }) => {
1253
await login(page, users.member);
1354
await page.goto("/", { waitUntil: "domcontentloaded" });
1455

15-
await expect(
16-
page.getByRole("button", { name: "Admin settings" }),
17-
).not.toBeVisible();
56+
// None, "Admin settings" button should not be visible
57+
await hasAccessToAdminSettings(page, []);
1858
});
1959

20-
test("template admin can see deployment settings", async ({ page }) => {
60+
test("template admin can see admin settings", async ({ page }) => {
2161
await login(page, users.templateAdmin);
2262
await page.goto("/", { waitUntil: "domcontentloaded" });
2363

24-
await expect(
25-
page.getByRole("button", {
26-
name: "Admin settings",
27-
}),
28-
).toBeVisible();
64+
await hasAccessToAdminSettings(page, ["Deployment", "Organizations"]);
2965
});
3066

31-
test("user admin can see deployment settings", async ({ page }) => {
67+
test("user admin can see admin settings", async ({ page }) => {
3268
await login(page, users.userAdmin);
3369
await page.goto("/", { waitUntil: "domcontentloaded" });
3470

35-
await expect(
36-
page.getByRole("button", { name: "Admin settings" }),
37-
).toBeVisible();
71+
await hasAccessToAdminSettings(page, ["Deployment", "Organizations"]);
3872
});
3973

40-
test("auditor can see deployment settings", async ({ page }) => {
74+
test("auditor can see admin settings", async ({ page }) => {
4175
await login(page, users.auditor);
4276
await page.goto("/", { waitUntil: "domcontentloaded" });
4377

44-
await expect(
45-
page.getByRole("button", { name: "Admin settings" }),
46-
).toBeVisible();
78+
await hasAccessToAdminSettings(page, [
79+
"Deployment",
80+
"Organizations",
81+
"Audit Logs",
82+
]);
4783
});
4884

49-
test("admin can see deployment settings", async ({ page }) => {
85+
test("admin can see admin settings", async ({ page }) => {
5086
await login(page, users.admin);
5187
await page.goto("/", { waitUntil: "domcontentloaded" });
5288

53-
await expect(
54-
page.getByRole("button", { name: "Admin settings" }),
55-
).toBeVisible();
89+
await hasAccessToAdminSettings(page, [
90+
"Deployment",
91+
"Organizations",
92+
"Healthcheck",
93+
"Audit Logs",
94+
]);
95+
});
96+
});
97+
98+
test.describe("org-scoped roles admin settings access", () => {
99+
requiresLicense();
100+
101+
test.beforeEach(async ({ page }) => {
102+
await login(page);
103+
await setupApiCalls(page);
104+
});
105+
106+
test("org template admin can see admin settings", async ({ page }) => {
107+
const org = await createOrganization();
108+
const orgTemplateAdmin = await createOrganizationMember({
109+
[org.id]: ["organization-template-admin"],
110+
});
111+
112+
await login(page, orgTemplateAdmin);
113+
await page.goto("/", { waitUntil: "domcontentloaded" });
114+
115+
await hasAccessToAdminSettings(page, ["Organizations"]);
116+
});
117+
118+
test("org user admin can see admin settings", async ({ page }) => {
119+
const org = await createOrganization();
120+
const orgUserAdmin = await createOrganizationMember({
121+
[org.id]: ["organization-user-admin"],
122+
});
123+
124+
await login(page, orgUserAdmin);
125+
await page.goto("/", { waitUntil: "domcontentloaded" });
126+
127+
await hasAccessToAdminSettings(page, ["Deployment", "Organizations"]);
128+
});
129+
130+
test("org auditor can see admin settings", async ({ page }) => {
131+
const org = await createOrganization();
132+
const orgAuditor = await createOrganizationMember({
133+
[org.id]: ["organization-auditor"],
134+
});
135+
136+
await login(page, orgAuditor);
137+
await page.goto("/", { waitUntil: "domcontentloaded" });
138+
139+
await hasAccessToAdminSettings(page, ["Organizations", "Audit Logs"]);
140+
});
141+
142+
test("org admin can see admin settings", async ({ page }) => {
143+
const org = await createOrganization();
144+
const orgAdmin = await createOrganizationMember({
145+
[org.id]: ["organization-admin"],
146+
});
147+
148+
await login(page, orgAdmin);
149+
await page.goto("/", { waitUntil: "domcontentloaded" });
150+
151+
await hasAccessToAdminSettings(page, [
152+
"Deployment",
153+
"Organizations",
154+
"Audit Logs",
155+
]);
56156
});
57157
});

0 commit comments

Comments
 (0)