The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add tests for delete the link
Kiran K9642d6f4894d
diff --git a/apps/web/tests/links/create-link-error.test.ts b/apps/web/tests/links/create-link-error.test.tsindex 5c5ff5d306..079ebd2498 100644--- a/apps/web/tests/links/create-link-error.test.ts+++ b/apps/web/tests/links/create-link-error.test.ts@@ -2,9 +2,9 @@ import { Link } from "@prisma/client";import { expect, test } from "vitest";import { HttpClient } from "../utils/http";import { IntegrationHarness } from "../utils/integration";+import { link } from "../utils/resource";-const domain = "dub.sh";-const url = "https://github.com/dubinc";+const { domain, url } = link;const cases = [{@@ -67,6 +67,7 @@ cases.forEach(({ name, body, expected }) => {test(name, async (ctx) => {const h = new IntegrationHarness(ctx);const { workspace, apiKey } = await h.init();+ const { workspaceId } = workspace;const http = new HttpClient({baseUrl: h.baseUrl,@@ -77,7 +78,7 @@ cases.forEach(({ name, body, expected }) => {const response = await http.post<Link>({path: "/links",- query: { workspaceId: workspace.workspaceId },+ query: { workspaceId },body,});diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.tsindex ca70ea9854..8d9d2c668f 100644--- a/apps/web/tests/links/create-link.test.ts+++ b/apps/web/tests/links/create-link.test.ts@@ -4,6 +4,9 @@ import { afterAll, describe, expect, test } from "vitest";import { HttpClient } from "../utils/http";import { IntegrationHarness } from "../utils/integration";import { expectedLink } from "../utils/schema";+import { link } from "../utils/resource";++const { domain, url } = link;// TODO: Move this to shared// userId: user.id,@@ -13,9 +16,6 @@ import { expectedLink } from "../utils/schema";// qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,describe("create links with", async () => {- const url = "https://github.com/dubinc";- const domain = "dub.sh";-const h = new IntegrationHarness();const { workspace, apiKey, user } = await h.init();@@ -288,7 +288,7 @@ describe("create links with", async () => {};});- const { status, data: link } = await http.post<Link>({+ const { status, data: link } = await http.post<Link & { tags: [] }>({path: "/links",query: { workspaceId: workspace.workspaceId },body: {@@ -298,10 +298,11 @@ describe("create links with", async () => {});expect(status).toEqual(200);+ expect(link.tags).toHaveLength(2);expect(link).toMatchObject({...expectedLink,url,- tagId: tags[0].id,+ tagId: expect.any(String), // TODO: Fix thisuserId: user.id,projectId: workspace.id,workspaceId: workspace.workspaceId,diff --git a/apps/web/tests/links/delete-link.test.ts b/apps/web/tests/links/delete-link.test.tsnew file mode 100644index 0000000000..2ddce6404f--- /dev/null+++ b/apps/web/tests/links/delete-link.test.ts@@ -0,0 +1,51 @@+import { Link } from "@prisma/client";+import { expect, test } from "vitest";+import { HttpClient } from "../utils/http";+import { IntegrationHarness } from "../utils/integration";+import { link } from "../utils/resource";++const { domain, url } = link;++test("delete an existing link", async (ctx) => {+ const h = new IntegrationHarness(ctx);+ const { workspace, apiKey } = await h.init();+ const { workspaceId } = workspace;++ const http = new HttpClient({+ baseUrl: h.baseUrl,+ headers: {+ Authorization: `Bearer ${apiKey.token}`,+ },+ });++ const { data: link } = await http.post<Link>({+ path: "/links",+ query: { workspaceId },+ body: {+ url,+ domain,+ },+ });++ const { status, data } = await http.delete({+ path: `/links/${link.id}`,+ query: { workspaceId },+ });++ expect(status).toBe(200);+ expect(data).toMatchObject({+ id: link.id,+ });++ // Re-fetch the link+ const { status: status2 } = await http.get({+ path: "/links",+ query: {+ workspaceId,+ domain,+ key: link.key,+ },+ });++ expect(status2).toBe(404);+});diff --git a/apps/web/tests/links/list-links.test.ts b/apps/web/tests/links/list-links.test.tsindex d5785126b2..421ebccc61 100644--- a/apps/web/tests/links/list-links.test.ts+++ b/apps/web/tests/links/list-links.test.ts@@ -3,6 +3,9 @@ import { expect, test } from "vitest";import { HttpClient } from "../utils/http";import { IntegrationHarness } from "../utils/integration";import { expectedLink } from "../utils/schema";+import { link } from "../utils/resource";++const { domain, url } = link;test("list links", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +18,6 @@ test("list links", async (ctx) => {},});- const domain = "dub.sh";- const url = "https://github.com/dubinc";-// Create a linkconst { data: firstLink } = await http.post<Link>({path: "/links",diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.tsindex 94d660a73f..fde737d306 100644--- a/apps/web/tests/links/update-link.test.ts+++ b/apps/web/tests/links/update-link.test.ts@@ -4,10 +4,12 @@ import { expect, test } from "vitest";import { HttpClient } from "../utils/http";import { IntegrationHarness } from "../utils/integration";import { expectedLink } from "../utils/schema";+import { link } from "../utils/resource";++const { domain, url } = link;// TODO:// Archive Unarchive-// Delete// Transfer// Add/update/delete tags// Other links endpoints@@ -23,9 +25,6 @@ test("update an existing link", async (ctx) => {},});- const domain = "dub.sh";- const url = "https://github.com/dubinc";-const { data: link } = await http.post<Link>({path: "/links",query: { workspaceId: workspace.workspaceId },diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.tsnew file mode 100644index 0000000000..7064475625--- /dev/null+++ b/apps/web/tests/utils/resource.ts@@ -0,0 +1,4 @@+export const link = {+ domain: "dub.sh",+ url: "https://github.com/dubinc",+};