Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

1.6 KB
Raw Blame
import { Project, User } from "@prisma/client";
import { type TestContext } from "vitest";
import * as z from "zod/v4";
import { env, integrationTestEnv } from "./env";
import { HttpClient } from "./http";
import { E2E_USER_ID_MEMBER, E2E_WORKSPACE_ID } from "./resource";

interface Resources {
  user: Pick<User, "id">;
  workspace: Pick<Project, "id" | "slug" | "name"> & { workspaceId: string };
  apiKey: { token: string };
}

// for member user tests (folder access permissions)
export class IntegrationHarnessMember {
  private readonly ctx?: TestContext;
  private env: z.infer<typeof integrationTestEnv>;
  public resources: Resources;
  public baseUrl: string;
  public http: HttpClient;

  constructor(ctx?: TestContext) {
    this.env = env;
    this.ctx = ctx;
    this.baseUrl = this.env.E2E_BASE_URL;
    this.http = new HttpClient({
      baseUrl: `${this.baseUrl}/api`,
      headers: {
        Authorization: `Bearer ${this.env.E2E_TOKEN_MEMBER}`,
      },
    });
  }

  async init() {
    const user = {
      id: E2E_USER_ID_MEMBER,
    };

    const apiKey = {
      token: this.env.E2E_TOKEN_MEMBER,
    };

    const workspace = {
      id: E2E_WORKSPACE_ID,
      slug: "acme",
      name: "Acme, Inc.",
    };

    this.resources = {
      user,
      apiKey,
      workspace: {
        ...workspace,
        workspaceId: workspace.id,
      },
    };

    return { ...this.resources, http: this.http };
  }

  // Delete link
  public async deleteLink(id: string) {
    const { workspaceId } = this.resources.workspace;

    await this.http.delete({
      path: `/links/${id}`,
      query: { workspaceId },
    });
  }
}