The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Move folders API integration tests to Playwright.
Kiran K8f4ee22b3c22
diff --git a/apps/web/playwright/api/fixtures.ts b/apps/web/playwright/api/fixtures.tsindex f0af625fbd..478f35c78a 100644--- a/apps/web/playwright/api/fixtures.ts+++ b/apps/web/playwright/api/fixtures.ts@@ -9,9 +9,10 @@ type ApiResponse<T> = {data: T;};-type ApiClient = {+export type ApiClient = {get: <T>(url: string) => Promise<ApiResponse<T>>;post: <T>(url: string, data?: unknown) => Promise<ApiResponse<T>>;+ patch: <T>(url: string, data?: unknown) => Promise<ApiResponse<T>>;delete: <T>(url: string) => Promise<ApiResponse<T>>;};@@ -34,6 +35,8 @@ function createApiClient(request: APIRequestContext): ApiClient {get: <T>(url: string) => parse<T>(request.get(url)),post: <T>(url: string, data?: unknown) =>parse<T>(request.post(url, { data })),+ patch: <T>(url: string, data?: unknown) =>+ parse<T>(request.patch(url, { data })),delete: <T>(url: string) => parse<T>(request.delete(url)),};}diff --git a/apps/web/playwright/api/folders.spec.ts b/apps/web/playwright/api/folders.spec.tsnew file mode 100644index 0000000000..5567838328--- /dev/null+++ b/apps/web/playwright/api/folders.spec.ts@@ -0,0 +1,131 @@+import { expect } from "@playwright/test";+import type { Folder } from "@prisma/client";+import { randomName } from "../utils";+import { test, type ApiClient } from "./fixtures";++const expectedFolder = {+ id: expect.any(String),+ type: "default",+ description: null,+ createdAt: expect.any(String),+ updatedAt: expect.any(String),+};++async function createFolder(+ api: ApiClient,+ {+ name = randomName("folder"),+ accessLevel = "write",+ }: {+ name?: string;+ accessLevel?: string;+ } = {},+) {+ return api.post<Folder>("/api/folders", {+ name,+ accessLevel,+ });+}++async function deleteFolder(api: ApiClient, folderId: string) {+ await api.delete(`/api/folders/${folderId}`);+}++test.describe.configure({+ mode: "parallel",+});++test("POST /folders", async ({ api }) => {+ let folderId: string | undefined;+ const folderName = randomName("folder");++ try {+ const { status, data } = await createFolder(api, { name: folderName });+ folderId = data.id;++ expect(status).toEqual(201);+ expect(data).toStrictEqual({+ ...expectedFolder,+ name: folderName,+ accessLevel: "write",+ });+ } finally {+ if (folderId) {+ await deleteFolder(api, folderId);+ }+ }+});++test("GET /folders", async ({ api }) => {+ let folderId: string | undefined;++ try {+ const { data: folderCreated } = await createFolder(api);+ folderId = folderCreated.id;++ const { status, data } = await api.get<Folder[]>("/api/folders");++ expect(status).toBe(200);+ expect(data).toEqual(expect.arrayContaining([folderCreated]));+ } finally {+ if (folderId) {+ await deleteFolder(api, folderId);+ }+ }+});++test("PATCH /folders/{folderId}", async ({ api }) => {+ let folderId: string | undefined;+ const folderName = randomName("folder");++ try {+ const { data: folderCreated } = await createFolder(api, {+ name: folderName,+ });+ folderId = folderCreated.id;++ const { status, data } = await api.patch<Folder>(+ `/api/folders/${folderId}`,+ {+ name: `${folderName}-1`,+ accessLevel: "read",+ },+ );++ expect(status).toEqual(200);+ expect(data).toStrictEqual({+ ...expectedFolder,+ name: `${folderName}-1`,+ accessLevel: "read",+ });++ const { status: getStatus, data: persisted } = await api.get<Folder>(+ `/api/folders/${folderId}`,+ );++ expect(getStatus).toBe(200);+ expect(persisted).toStrictEqual(data);+ } finally {+ if (folderId) {+ await deleteFolder(api, folderId);+ }+ }+});++test("DELETE /folders/{folderId}", async ({ api }) => {+ const { data: folderCreated } = await createFolder(api);++ const { status, data } = await api.delete<{ id: string }>(+ `/api/folders/${folderCreated.id}`,+ );++ expect(status).toEqual(200);+ expect(data).toStrictEqual({+ id: folderCreated.id,+ });++ const { status: getStatus } = await api.get(+ `/api/folders/${folderCreated.id}`,+ );+ expect(getStatus).toEqual(404);+});diff --git a/apps/web/playwright/tsconfig.json b/apps/web/playwright/tsconfig.jsonnew file mode 100644index 0000000000..4f0fca2bc4--- /dev/null+++ b/apps/web/playwright/tsconfig.json@@ -0,0 +1,24 @@+{+ "compilerOptions": {+ "target": "ESNext",+ "module": "esnext",+ "moduleResolution": "bundler",+ "strict": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "resolveJsonModule": true,+ "types": [+ "node"+ ],+ "baseUrl": "..",+ "paths": {+ "@/*": [+ "./*"+ ]+ }+ },+ "include": [+ "./**/*.ts",+ "../global-setup.ts"+ ]+}\ No newline at end of filediff --git a/apps/web/tests/folders/index.test.ts b/apps/web/tests/folders/index.test.tsdeleted file mode 100644index 27d26e958d..0000000000--- a/apps/web/tests/folders/index.test.ts+++ /dev/null@@ -1,91 +0,0 @@-import { FolderSchema } from "@/lib/zod/schemas/folders";-import { randomId } from "tests/utils/helpers";-import { describe, expect, test } from "vitest";-import * as z from "zod/v4";-import { IntegrationHarness } from "../utils/integration";--type FolderRecord = z.infer<typeof FolderSchema>;--const expectedFolder = {- id: expect.any(String),- type: "default",- description: null,- createdAt: expect.any(String),- updatedAt: expect.any(String),-};--describe.sequential("/folders/**", async () => {- const h = new IntegrationHarness();- const { workspace, http } = await h.init();-- let folderCreated: FolderRecord | undefined;- const folderName = randomId();-- test("POST /folders", async () => {- const { status, data } = await http.post<FolderRecord>({- path: "/folders",- query: {- workspaceId: workspace.id,- },- body: {- name: folderName,- accessLevel: "write",- },- });-- folderCreated = data;-- expect(status).toEqual(201);- expect(data).toStrictEqual({- ...expectedFolder,- name: folderName,- accessLevel: "write",- });- });-- test("GET /folders", async () => {- const { status, data } = await http.get<FolderRecord[]>({- path: "/folders",- query: {- workspaceId: workspace.id,- },- });-- expect(status).toEqual(200);- expect(data).toContainEqual(folderCreated);- });-- test("PATCH /folders/{folderId}", { retry: 3 }, async () => {- const { status, data } = await http.patch<FolderRecord>({- path: `/folders/${folderCreated?.id}`,- query: {- workspaceId: workspace.id,- },- body: {- name: `${folderName}-1`,- accessLevel: "read",- },- });-- expect(status).toEqual(200);- expect(data).toStrictEqual({- ...expectedFolder,- name: `${folderName}-1`,- accessLevel: "read",- });- });-- test("DELETE /folders/{folderId}", async () => {- const { status, data } = await http.delete<{ id: string }>({- path: `/folders/${folderCreated?.id}`,- query: {- workspaceId: workspace.id,- },- });-- expect(status).toEqual(200);- expect(data).toStrictEqual({- id: folderCreated?.id,- });- });-});