The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add some tests
Kiran Kbdc40805a7ad
diff --git a/apps/web/tests/folders/index.test.ts b/apps/web/tests/folders/index.test.tsnew file mode 100644index 0000000000..51ce88e536--- /dev/null+++ b/apps/web/tests/folders/index.test.ts@@ -0,0 +1,70 @@+import z from "@/lib/zod";+import { folderSchema } from "@/lib/zod/schemas/folders";+import { Folder } from "@prisma/client";+import { describe, expect, test } from "vitest";+import { IntegrationHarness } from "../utils/integration";++type FolderRecord = z.infer<typeof folderSchema>;++describe.sequential("/folders/**", async () => {+ const h = new IntegrationHarness();+ const { workspace, http } = await h.init();++ let folderCreated: FolderRecord | undefined;++ test("POST /folders", async () => {+ const { status, data } = await http.post<Folder>({+ path: "/folders",+ query: { workspaceId: workspace.id },+ body: {+ name: "Documents",+ },+ });++ folderCreated = data;++ expect(status).toEqual(201);+ expect(data).toStrictEqual({+ id: expect.any(String),+ name: "Documents",+ });+ });++ 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: "Documents-1",+ },+ });++ expect(status).toEqual(200);+ expect(data).toStrictEqual({+ id: expect.any(String),+ name: "Documents-1",+ });+ });++ 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,+ });+ });+});diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.tsindex 387e300335..308fde7f53 100644--- a/apps/web/tests/links/create-link.test.ts+++ b/apps/web/tests/links/create-link.test.ts@@ -1,3 +1,5 @@+import z from "@/lib/zod";+import { folderSchema } from "@/lib/zod/schemas/folders";import { LinkSchema } from "@/lib/zod/schemas/links";import { Link, Tag } from "@prisma/client";import { IntegrationHarnessOld } from "tests/utils/integration-old";@@ -7,6 +9,8 @@ import { IntegrationHarness } from "../utils/integration";import { link } from "../utils/resource";import { expectedLink } from "../utils/schema";+type FolderRecord = z.infer<typeof folderSchema>;+const { domain, url } = link;describe.sequential("POST /links", async () => {@@ -368,6 +372,40 @@ describe.sequential("POST /links", async () => {});});+ test("folders", async () => {+ const { data: folder } = await http.post<FolderRecord>({+ path: "/folders",+ body: { name: randomId() },+ });++ const { status, data: link } = await http.post<Link>({+ path: "/links",+ body: {+ url,+ domain,+ folderId: folder.id,+ },+ });++ expect(status).toEqual(200);+ expect(link.folderId).toEqual(folder.id);+ expect(LinkSchema.strict().parse(link)).toBeTruthy();+ expect(link).toStrictEqual({+ ...expectedLink,+ url,+ folderId: folder.id,+ userId: user.id,+ projectId,+ workspaceId,+ shortLink: `https://${domain}/${link.key}`,+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,+ });++ afterAll(async () => {+ await Promise.all([h.deleteFolder(folder.id), h.deleteLink(link.id)]);+ });+ });+test("custom social media cards", async () => {const title = "custom title";const description = "custom description";