Ctrl K
ComunidadGuías…

tests/seed-test.ts

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
/* oxlint-disable no-empty-pattern */
import { test as base } from "@playwright/test";

import type {
  Account,
  Plan,
  Project,
  Team,
  User,
} from "../apps/backend/src/database/models";
import { Plan as PlanModel } from "../apps/backend/src/database/models";
import {
  BuildScenario,
  createBuildScenario,
  createProject,
  createTeamAccount,
  createUserAccount,
} from "../apps/backend/src/database/seeds";
import { getUniqueTestIdentifier } from "./util";

type TestFixtures = {
  user: { user: User; account: Account };
  team: { team: Team; account: Account };
  project: Project;
  builds: BuildScenario;
};

type WorkerFixtures = {
  plan: Plan;
};

export const seedTest = base.extend<TestFixtures, WorkerFixtures>({
  user: async ({}, use, testInfo) => {
    const id = getUniqueTestIdentifier(testInfo);
    const user = await createUserAccount({
      email: `kyle-${id}@acme.com`,
      name: "Kyle Bertolino",
      slug: `kyle-${id}`,
    });
    await use(user);
  },
  plan: [
    async ({}, use) => {
      const plan = await PlanModel.query().insertAndFetch({
        // The name production uses, which the staff pipeline compares against
        // to decide whether a row's plan is worth naming.
        name: "pro",
        includedScreenshots: 15000,
        githubPlanId: null,
        stripeProductId: null,
        usageBased: false,
        githubSsoIncluded: true,
        fineGrainedAccessControlIncluded: true,
        samlIncluded: true,
        interval: "month",
      });
      await use(plan);
    },
    { scope: "worker" },
  ],
  team: async ({ plan }, use, testInfo) => {
    const id = getUniqueTestIdentifier(testInfo);
    const slug = `acme-${id}`;
    const team = await createTeamAccount({
      slug,
      name: "Acme",
      forcedPlanId: plan.id,
    });
    await use(team);
  },
  project: async ({ team }, use) => {
    const project = await createProject({
      accountId: team.account.id,
      name: "sparkle",
    });
    await use(project);
  },
  builds: async ({ project }, use) => {
    const builds = await createBuildScenario({
      projectId: project.id,
    });
    await use(builds);
  },
});