import { test as base } from "@playwright/test";
import { createUser } from "../utils/user-factory";

export type Actor = "user";

const ACTOR_PERMISSIONS: Record<Actor, string[]> = {
  user: [
    "user-management:user",
    "user-management:role",
    "user-management:roleAssignment",
    "user-management:profile",
  ],
};

type UserFixture = Awaited<ReturnType<typeof createUser>>;

interface WorkerFixtures {
  User: UserFixture;
}

export const test = base.extend<object, WorkerFixtures>({
  User: [
    // oxlint-disable-next-line no-empty-pattern
    async ({}, use) => {
      const user = await createUser({ permissions: ACTOR_PERMISSIONS.user });
      await use(user);
    },
    { scope: "worker" },
  ],
});

export const expect = test.expect;
