add e2e tests for employee restrictions

This commit is contained in:
Gregor Vostrak
2026-02-10 14:41:04 +01:00
parent e45662c715
commit 8be55359ce
21 changed files with 1211 additions and 37 deletions

View File

@@ -1,17 +1,27 @@
import { test as baseTest } from '@playwright/test';
import type { Page } from '@playwright/test';
import { PLAYWRIGHT_BASE_URL, TEST_USER_PASSWORD } from './config';
import { type TestContext, setupTestContext } from '../e2e/utils/api';
import { setupEmployeeUser } from '../e2e/utils/members';
export * from '@playwright/test';
export type { TestContext };
export interface EmployeeFixture {
page: Page;
memberId: string;
}
/**
* API-based authentication fixture - creates a new user via HTTP requests instead of UI interactions.
* This is ~10-25x faster than UI-based authentication (~100-200ms vs ~3-5s).
*
* Uses page.context().request() to ensure cookies are shared between the API request and page.
*/
export const test = baseTest.extend<{ ctx: TestContext }, { workerStorageState: string }>({
export const test = baseTest.extend<
{ ctx: TestContext; employee: EmployeeFixture },
{ workerStorageState: string }
>({
page: async ({ page }, use) => {
// Generate unique email for this test
const email = `john+${Date.now()}_${Math.floor(Math.random() * 10000)}@doe.com`;
@@ -80,4 +90,14 @@ export const test = baseTest.extend<{ ctx: TestContext }, { workerStorageState:
const ctx = await setupTestContext(page);
await use(ctx);
},
employee: async ({ page, ctx, browser }, use) => {
const { employeePage, employeeMemberId, closeEmployee } = await setupEmployeeUser(
page,
ctx,
browser
);
await use({ page: employeePage, memberId: employeeMemberId });
await closeEmployee();
},
});