Files
calendar/apps/web/playwright/impersonation.e2e.ts
T
60e0bbf4b7 feat: impersonation improvements (#13066)
* fix: rename checkPermission to be more fitting

* feat:return to user

* nits: cleanup plus comments

* cleanup

* test: Add e2e

* fix: fix fixtures

* nit: cleanup logs

* chore: move to impersonatedBy in session

* fix: can return to self

* Update apps/web/playwright/impersonation.e2e.ts

* fix: typecheck

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
2024-01-16 08:45:48 +00:00

51 lines
1.7 KiB
TypeScript

import { expect } from "@playwright/test";
import { test } from "./lib/fixtures";
test.describe.configure({ mode: "parallel" });
test.describe("Users can impersonate", async () => {
test.afterAll(async ({ users }) => {
await users.deleteAll();
});
test("App Admin can impersonate users with impersonation enabled", async ({ page, users }) => {
// log in trail user
const user = await users.create({
role: "ADMIN",
password: "ADMINadmin2022!",
});
const userToImpersonate = await users.create({ disableImpersonation: false });
await user.apiLogin();
await page.waitForLoadState();
await page.goto("/settings/admin/impersonation");
await page.waitForLoadState();
const adminInput = page.getByTestId("admin-impersonation-input");
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore the username does exist
await adminInput.fill(userToImpersonate.username);
await page.getByTestId("impersonation-submit").click();
// // Wait for sign in to complete
await page.waitForURL("/settings/my-account/profile");
const stopImpersonatingButton = page.getByTestId("stop-impersonating-button");
const impersonatedUsernameInput = page.locator("input[name='username']");
const impersonatedUser = await impersonatedUsernameInput.inputValue();
await expect(stopImpersonatingButton).toBeVisible();
await expect(impersonatedUser).toBe(userToImpersonate.username);
await stopImpersonatingButton.click();
await page.waitForLoadState("networkidle");
// Return to user
const ogUser = await impersonatedUsernameInput.inputValue();
expect(ogUser).toBe(user.username);
});
});