Skip to content

Commit 49a35e3

Browse files
authored
chore: add e2e tests for organization auditors (coder#16899)
1 parent 75b27e8 commit 49a35e3

File tree

4 files changed

+129
-16
lines changed

4 files changed

+129
-16
lines changed

site/e2e/api.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,25 @@ export const createUser = async (...orgIds: string[]) => {
3838
return user;
3939
};
4040

41-
export const createOrganizationMember = async (
42-
orgRoles: Record<string, string[]>,
43-
): Promise<LoginOptions> => {
41+
type CreateOrganizationMemberOptions = {
42+
username?: string;
43+
email?: string;
44+
password?: string;
45+
orgRoles: Record<string, string[]>;
46+
};
47+
48+
export const createOrganizationMember = async ({
49+
username = randomName(),
50+
email = `${username}@coder.com`,
51+
password = defaultPassword,
52+
orgRoles,
53+
}: CreateOrganizationMemberOptions): Promise<LoginOptions> => {
4454
const name = randomName();
4555
const user = await API.createUser({
46-
email: `${name}@coder.com`,
47-
username: name,
48-
name: name,
49-
password: defaultPassword,
56+
email,
57+
username,
58+
name: username,
59+
password,
5060
login_type: "password",
5161
organization_ids: Object.keys(orgRoles),
5262
user_status: null,
@@ -59,7 +69,7 @@ export const createOrganizationMember = async (
5969
return {
6070
username: user.username,
6171
email: user.email,
62-
password: defaultPassword,
72+
password,
6373
};
6474
};
6575

@@ -74,8 +84,7 @@ export const createGroup = async (orgId: string) => {
7484
return group;
7585
};
7686

77-
export const createOrganization = async () => {
78-
const name = randomName();
87+
export const createOrganization = async (name = randomName()) => {
7988
const org = await API.createOrganization({
8089
name,
8190
display_name: `Org ${name}`,

site/e2e/tests/organizationGroups.spec.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ test("create group", async ({ page }) => {
3434
// Create a new organization
3535
const org = await createOrganization();
3636
const orgUserAdmin = await createOrganizationMember({
37-
[org.id]: ["organization-user-admin"],
37+
orgRoles: {
38+
[org.id]: ["organization-user-admin"],
39+
},
3840
});
3941

4042
await login(page, orgUserAdmin);
@@ -99,7 +101,9 @@ test("change quota settings", async ({ page }) => {
99101
const org = await createOrganization();
100102
const group = await createGroup(org.id);
101103
const orgUserAdmin = await createOrganizationMember({
102-
[org.id]: ["organization-user-admin"],
104+
orgRoles: {
105+
[org.id]: ["organization-user-admin"],
106+
},
103107
});
104108

105109
// Go to settings
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { type Page, expect, test } from "@playwright/test";
2+
import {
3+
createOrganization,
4+
createOrganizationMember,
5+
setupApiCalls,
6+
} from "../../api";
7+
import { defaultPassword, users } from "../../constants";
8+
import { login, randomName, requiresLicense } from "../../helpers";
9+
import { beforeCoderTest } from "../../hooks";
10+
11+
test.describe.configure({ mode: "parallel" });
12+
13+
const orgName = randomName();
14+
15+
const orgAuditor = {
16+
username: `org-auditor-${orgName}`,
17+
password: defaultPassword,
18+
email: `org-auditor-${orgName}@coder.com`,
19+
};
20+
21+
test.beforeEach(({ page }) => {
22+
beforeCoderTest(page);
23+
});
24+
25+
test.describe("organization scoped audit logs", () => {
26+
requiresLicense();
27+
28+
test.beforeAll(async ({ browser }) => {
29+
const context = await browser.newContext();
30+
const page = await context.newPage();
31+
32+
await login(page);
33+
await setupApiCalls(page);
34+
35+
const org = await createOrganization(orgName);
36+
await createOrganizationMember({
37+
...orgAuditor,
38+
orgRoles: {
39+
[org.id]: ["organization-auditor"],
40+
},
41+
});
42+
43+
await context.close();
44+
});
45+
46+
test("organization auditors cannot see logins", async ({ page }) => {
47+
// Go to the audit history
48+
await login(page, orgAuditor);
49+
await page.goto("/audit");
50+
const username = orgAuditor.username;
51+
52+
const loginMessage = `${username} logged in`;
53+
// Make sure those things we did all actually show up
54+
await expect(page.getByText(loginMessage).first()).not.toBeVisible();
55+
});
56+
57+
test("creating organization is logged", async ({ page }) => {
58+
await login(page, orgAuditor);
59+
60+
// Go to the audit history
61+
await page.goto("/audit", { waitUntil: "domcontentloaded" });
62+
63+
const auditLogText = `${users.owner.username} created organization ${orgName}`;
64+
const org = page.locator(".MuiTableRow-root", {
65+
hasText: auditLogText,
66+
});
67+
await org.scrollIntoViewIfNeeded();
68+
await expect(org).toBeVisible();
69+
70+
await org.getByLabel("open-dropdown").click();
71+
await expect(org.getByText(`icon: "/emojis/1f957.png"`)).toBeVisible();
72+
});
73+
74+
test("assigning an organization role is logged", async ({ page }) => {
75+
await login(page, orgAuditor);
76+
77+
// Go to the audit history
78+
await page.goto("/audit", { waitUntil: "domcontentloaded" });
79+
80+
const auditLogText = `${users.owner.username} updated organization member ${orgAuditor.username}`;
81+
const member = page.locator(".MuiTableRow-root", {
82+
hasText: auditLogText,
83+
});
84+
await member.scrollIntoViewIfNeeded();
85+
await expect(member).toBeVisible();
86+
87+
await member.getByLabel("open-dropdown").click();
88+
await expect(
89+
member.getByText(`roles: ["organization-auditor"]`),
90+
).toBeVisible();
91+
});
92+
});

site/e2e/tests/roles.spec.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ test.describe("org-scoped roles admin settings access", () => {
106106
test("org template admin can see admin settings", async ({ page }) => {
107107
const org = await createOrganization();
108108
const orgTemplateAdmin = await createOrganizationMember({
109-
[org.id]: ["organization-template-admin"],
109+
orgRoles: {
110+
[org.id]: ["organization-template-admin"],
111+
},
110112
});
111113

112114
await login(page, orgTemplateAdmin);
@@ -118,7 +120,9 @@ test.describe("org-scoped roles admin settings access", () => {
118120
test("org user admin can see admin settings", async ({ page }) => {
119121
const org = await createOrganization();
120122
const orgUserAdmin = await createOrganizationMember({
121-
[org.id]: ["organization-user-admin"],
123+
orgRoles: {
124+
[org.id]: ["organization-user-admin"],
125+
},
122126
});
123127

124128
await login(page, orgUserAdmin);
@@ -130,7 +134,9 @@ test.describe("org-scoped roles admin settings access", () => {
130134
test("org auditor can see admin settings", async ({ page }) => {
131135
const org = await createOrganization();
132136
const orgAuditor = await createOrganizationMember({
133-
[org.id]: ["organization-auditor"],
137+
orgRoles: {
138+
[org.id]: ["organization-auditor"],
139+
},
134140
});
135141

136142
await login(page, orgAuditor);
@@ -142,7 +148,9 @@ test.describe("org-scoped roles admin settings access", () => {
142148
test("org admin can see admin settings", async ({ page }) => {
143149
const org = await createOrganization();
144150
const orgAdmin = await createOrganizationMember({
145-
[org.id]: ["organization-admin"],
151+
orgRoles: {
152+
[org.id]: ["organization-admin"],
153+
},
146154
});
147155

148156
await login(page, orgAdmin);

0 commit comments

Comments
 (0)