The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
test: move externalId clear coverage to Vitest create-link suite
Cursor Agenteb5d9c3320cb
diff --git a/apps/web/playwright/api/links/links.spec.ts b/apps/web/playwright/api/links/links.spec.tsdeleted file mode 100644index 7ba748d5b7..0000000000--- a/apps/web/playwright/api/links/links.spec.ts+++ /dev/null@@ -1,86 +0,0 @@-import { nanoid } from "@dub/utils";-import { expect } from "@playwright/test";-import { test, type ApiClient } from "../fixtures";-import { TEST_WORKSPACE } from "../setup-test-workspace";--type Link = {- id: string;- url: string;- domain: string;- externalId: string | null;-};--const domain = TEST_WORKSPACE.program.domain;--async function createLink(- api: ApiClient,- overrides: Record<string, unknown> = {},-) {- return api.post<Link>("/api/links", {- url: `https://example.com/${nanoid()}`,- domain,- key: nanoid(12),- ...overrides,- });-}--async function deleteLink(api: ApiClient, id: string | undefined) {- if (!id) return;- await api.delete(`/api/links/${id}`);-}--test("PATCH /links/:id – clear externalId with empty string", async ({- api,-}) => {- let linkId: string | undefined;- const externalId = nanoid(12);-- try {- const { status: createStatus, data: created } = await createLink(api, {- externalId,- });- linkId = created.id;-- expect(createStatus).toEqual(200);- expect(created.externalId).toEqual(externalId);-- const { status, data: updated } = await api.patch<Link>(- `/api/links/${created.id}`,- { externalId: "" },- );-- expect(status).toEqual(200);- expect(updated.externalId).toBeNull();-- const { status: getStatus, data: fetched } = await api.get<Link>(- `/api/links/${created.id}`,- );-- expect(getStatus).toEqual(200);- expect(fetched.externalId).toBeNull();- } finally {- await deleteLink(api, linkId);- }-});--test("PATCH /links/:id – clear externalId with null", async ({ api }) => {- let linkId: string | undefined;- const externalId = nanoid(12);-- try {- const { data: created } = await createLink(api, { externalId });- linkId = created.id;-- expect(created.externalId).toEqual(externalId);-- const { status, data: updated } = await api.patch<Link>(- `/api/links/${created.id}`,- { externalId: null },- );-- expect(status).toEqual(200);- expect(updated.externalId).toBeNull();- } finally {- await deleteLink(api, linkId);- }-});diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.tsindex 6956858084..f7db30dd7a 100644--- a/apps/web/tests/links/create-link.test.ts+++ b/apps/web/tests/links/create-link.test.ts@@ -81,6 +81,66 @@ describe.sequential("POST /links", async () => {expect(LinkSchema.strict().parse(link)).toBeTruthy();});+ test("clear externalId with empty string", async ({ onTestFinished }) => {+ const externalId = randomId();++ const { data: link } = await http.post<Link>({+ path: "/links",+ body: {+ url,+ domain,+ externalId,+ },+ });++ onTestFinished(async () => {+ await h.deleteLink(link.id);+ });++ expect(link.externalId).toEqual(externalId);++ const { status, data: updated } = await http.patch<Link>({+ path: `/links/${link.id}`,+ body: { externalId: "" },+ });++ expect(status).toEqual(200);+ expect(updated.externalId).toEqual(null);++ const { data: fetched } = await http.get<Link>({+ path: `/links/${link.id}`,+ });++ expect(fetched.externalId).toEqual(null);+ });++ test("clear externalId with null", async ({ onTestFinished }) => {+ const externalId = randomId();++ const { data: link } = await http.post<Link>({+ path: "/links",+ body: {+ url,+ domain,+ externalId,+ },+ });++ onTestFinished(async () => {+ await h.deleteLink(link.id);+ });++ expect(link.externalId).toEqual(externalId);++ const { status, data: updated } = await http.patch<Link>({+ path: `/links/${link.id}`,+ body: { externalId: null },+ });++ expect(status).toEqual(200);+ expect(updated.externalId).toEqual(null);+ });+test("user defined key", async ({ onTestFinished }) => {const key = randomId();diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.tsindex c1601096e0..3dd59b1e7f 100644--- a/apps/web/tests/links/update-link.test.ts+++ b/apps/web/tests/links/update-link.test.ts@@ -179,43 +179,6 @@ describe.sequential("PATCH /links/{linkId}", async () => {expect(linkUpdated.url).toEqual("https://github.com/dubinc");});-- test("remove externalId with empty string", async () => {- const { status, data: updatedLink } = await http.patch<Link>({- path: `/links/${link.id}`,- body: {- externalId: "",- },- });-- expect(status).toEqual(200);- expect(updatedLink.externalId).toEqual(null);-- const { data: fetchedLink } = await http.get<Link>({- path: `/links/${link.id}`,- });-- expect(fetchedLink.externalId).toEqual(null);- });-- test("remove externalId with null", async () => {- // Re-set an externalId first so we can clear it again- const newExternalId = randomId();- await http.patch<Link>({- path: `/links/${link.id}`,- body: { externalId: newExternalId },- });-- const { status, data: updatedLink } = await http.patch<Link>({- path: `/links/${link.id}`,- body: {- externalId: null,- },- });-- expect(status).toEqual(200);- expect(updatedLink.externalId).toEqual(null);- });});describe.sequential("PATCH /links/{linkId} - UTM parameters", async () => {