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.

Move workspace retrieve API tests to Playwright.

Kiran Kcf7aef0bdafd
diff --git a/apps/web/playwright/api/fixtures.ts b/apps/web/playwright/api/fixtures.ts
index 478f35c78a..e5c0461879 100644
--- a/apps/web/playwright/api/fixtures.ts
+++ b/apps/web/playwright/api/fixtures.ts
@@ -16,8 +16,12 @@ export type ApiClient = {
delete: <T>(url: string) => Promise<ApiResponse<T>>;
};
-function loadApiAuth(): { token: string } {
- return JSON.parse(readFileSync(authFile, "utf-8")) as { token: string };
+function loadApiAuth() {
+ return JSON.parse(readFileSync(authFile, "utf-8")) as {
+ token: string;
+ workspaceId: string;
+ workspaceSlug: string;
+ };
}
function createApiClient(request: APIRequestContext): ApiClient {
@@ -41,7 +45,10 @@ function createApiClient(request: APIRequestContext): ApiClient {
};
}
-export const test = base.extend<{ api: ApiClient }>({
+export const test = base.extend<{
+ api: ApiClient;
+ workspace: { id: string; slug: string };
+}>({
// Authenticated API request context (token from globalSetup → .auth/api.json).
request: async ({ playwright, baseURL }, use) => {
const { token } = loadApiAuth();
@@ -59,4 +66,9 @@ export const test = base.extend<{ api: ApiClient }>({
api: async ({ request }, use) => {
await use(createApiClient(request));
},
+
+ workspace: async ({}, use) => {
+ const { workspaceId, workspaceSlug } = loadApiAuth();
+ await use({ id: workspaceId, slug: workspaceSlug });
+ },
});
diff --git a/apps/web/playwright/api/workspaces.spec.ts b/apps/web/playwright/api/workspaces.spec.ts
new file mode 100644
index 0000000000..969871dd8c
--- /dev/null
+++ b/apps/web/playwright/api/workspaces.spec.ts
@@ -0,0 +1,61 @@
+import { WorkspaceSchema } from "@/lib/zod/schemas/workspaces";
+import { expect } from "@playwright/test";
+import type { Project } from "@prisma/client";
+import * as z from "zod/v4";
+import { test } from "./fixtures";
+import { TEST_WORKSPACE } from "./setup-test-workspace";
+
+test.describe.configure({
+ mode: "parallel",
+});
+
+test("GET /workspaces/{idOrSlug} – by id", async ({ api, workspace }) => {
+ const { status, data: workspaceFetched } = await api.get<Project>(
+ `/api/workspaces/${workspace.id}`,
+ );
+
+ const { id, name, slug } = workspaceFetched;
+
+ expect(status).toEqual(200);
+ expect({ id, name, slug }).toStrictEqual({
+ id: workspace.id,
+ name: TEST_WORKSPACE.workspace.name,
+ slug: workspace.slug,
+ });
+
+ WorkspaceSchema.extend({
+ createdAt: z.string(),
+ }).parse(workspaceFetched);
+});
+
+test("GET /workspaces/{idOrSlug} – by slug", async ({ api, workspace }) => {
+ const { status, data: workspaceFetched } = await api.get<Project>(
+ `/api/workspaces/${workspace.slug}`,
+ );
+
+ const { id, name, slug } = workspaceFetched;
+
+ expect(status).toEqual(200);
+ expect({ id, name, slug }).toStrictEqual({
+ id: workspace.id,
+ name: TEST_WORKSPACE.workspace.name,
+ slug: workspace.slug,
+ });
+
+ WorkspaceSchema.extend({
+ createdAt: z.string(),
+ }).parse(workspaceFetched);
+});
+
+test("GET /workspaces/{idOrSlug} – invalid slug or id", async ({ api }) => {
+ const { status, data: error } = await api.get(`/api/workspaces/xxxx`);
+
+ expect(status).toEqual(404);
+ expect(error).toStrictEqual({
+ error: {
+ code: "not_found",
+ message: "Workspace not found.",
+ doc_url: "https://dub.co/docs/api-reference/errors#not-found",
+ },
+ });
+});
diff --git a/apps/web/tests/workspaces/retrieve-workspace.error.test.ts b/apps/web/tests/workspaces/retrieve-workspace.error.test.ts
deleted file mode 100644
index 995ca60942..0000000000
--- a/apps/web/tests/workspaces/retrieve-workspace.error.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { Project } from "@prisma/client";
-import { expect, test } from "vitest";
-import { IntegrationHarness } from "../utils/integration";
-
-test("retrieve a workspace by invalid slug or id", async (ctx) => {
- const h = new IntegrationHarness(ctx);
- const { http } = await h.init();
-
- const { status, data: error } = await http.get<Project>({
- path: `/workspaces/xxxx`,
- });
-
- expect(status).toEqual(404);
- expect(error).toStrictEqual({
- error: {
- code: "not_found",
- message: "Workspace not found.",
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- });
-});
diff --git a/apps/web/tests/workspaces/retrieve-workspace.test.ts b/apps/web/tests/workspaces/retrieve-workspace.test.ts
deleted file mode 100644
index bb9b2fe307..0000000000
--- a/apps/web/tests/workspaces/retrieve-workspace.test.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { WorkspaceSchema } from "@/lib/zod/schemas/workspaces";
-import { Project } from "@prisma/client";
-import { describe, expect, test } from "vitest";
-import * as z from "zod/v4";
-import { IntegrationHarness } from "../utils/integration";
-
-describe("GET /workspaces/{idOrSlug}", async () => {
- const h = new IntegrationHarness();
- const { workspace, http } = await h.init();
-
- test("by id", async () => {
- const { status, data: workspaceFetched } = await http.get<Project>({
- path: `/workspaces/${workspace.id}`,
- });
-
- const { id, name, slug } = workspaceFetched;
-
- expect(status).toEqual(200);
- expect({ id, name, slug }).toStrictEqual({
- id: workspace.id,
- name: workspace.name,
- slug: workspace.slug,
- });
-
- WorkspaceSchema.extend({
- createdAt: z.string(),
- }).parse(workspaceFetched);
- });
-
- test("by slug", async () => {
- const { status, data: workspaceFetched } = await http.get<Project>({
- path: `/workspaces/${workspace.slug}`,
- });
-
- const { id, name, slug } = workspaceFetched;
-
- expect(status).toEqual(200);
- expect({ id, name, slug }).toStrictEqual({
- id: workspace.id,
- name: workspace.name,
- slug: workspace.slug,
- });
-
- WorkspaceSchema.extend({
- createdAt: z.string(),
- }).parse(workspaceFetched);
- });
-});