The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve update links tests
Kiran K37367fb67cf5
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.tsindex 8d9d2c668f..ca18617877 100644--- a/apps/web/tests/links/create-link.test.ts+++ b/apps/web/tests/links/create-link.test.ts@@ -15,7 +15,7 @@ const { domain, url } = link;// shortLink: `https://${domain}/${link.key}`,// qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,-describe("create links with", async () => {+describe("create a link with", async () => {const h = new IntegrationHarness();const { workspace, apiKey, user } = await h.init();diff --git a/apps/web/tests/links/list-links.test.ts b/apps/web/tests/links/list-links.test.tsindex 421ebccc61..07a29c11ec 100644--- a/apps/web/tests/links/list-links.test.ts+++ b/apps/web/tests/links/list-links.test.ts@@ -10,6 +10,7 @@ const { domain, url } = link;test("list links", async (ctx) => {const h = new IntegrationHarness(ctx);const { workspace, apiKey, user } = await h.init();+ const { workspaceId, id: projectId } = workspace;const http = new HttpClient({baseUrl: h.baseUrl,@@ -21,7 +22,7 @@ test("list links", async (ctx) => {// Create a linkconst { data: firstLink } = await http.post<Link>({path: "/links",- query: { workspaceId: workspace.workspaceId },+ query: { workspaceId },body: { url, domain },});@@ -31,14 +32,14 @@ test("list links", async (ctx) => {// Create another linkconst { data: secondLink } = await http.post<Link>({path: "/links",- query: { workspaceId: workspace.workspaceId },+ query: { workspaceId },body: { url, domain },});// List linksconst { data: links, status } = await http.get<Link[]>({path: "/links",- query: { workspaceId: workspace.workspaceId },+ query: { workspaceId },});expect(status).toEqual(200);@@ -49,8 +50,8 @@ test("list links", async (ctx) => {domain,url,userId: user.id,- projectId: workspace.id,- workspaceId: workspace.workspaceId,+ projectId,+ workspaceId,tags: [],shortLink: `https://${domain}/${secondLink.key}`,qrCode: `https://api.dub.co/qr?url=https://${domain}/${secondLink.key}?qr=1`,@@ -61,8 +62,8 @@ test("list links", async (ctx) => {domain,url,userId: user.id,- projectId: workspace.id,- workspaceId: workspace.workspaceId,+ projectId,+ workspaceId,tags: [],shortLink: `https://${domain}/${firstLink.key}`,qrCode: `https://api.dub.co/qr?url=https://${domain}/${firstLink.key}?qr=1`,diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.tsindex fde737d306..a0994f7d02 100644--- a/apps/web/tests/links/update-link.test.ts+++ b/apps/web/tests/links/update-link.test.ts@@ -1,6 +1,6 @@import { nanoid } from "@dub/utils";import { Link } from "@prisma/client";-import { expect, test } from "vitest";+import { expect, test, describe, afterAll } from "vitest";import { HttpClient } from "../utils/http";import { IntegrationHarness } from "../utils/integration";import { expectedLink } from "../utils/schema";@@ -9,14 +9,13 @@ import { link } from "../utils/resource";const { domain, url } = link;// TODO:-// Archive Unarchive-// Transfer+// Update other fields// Add/update/delete tags-// Other links endpoints-test("update an existing link", async (ctx) => {- const h = new IntegrationHarness(ctx);+describe("PUT - /links/{linkId}", async () => {+ const h = new IntegrationHarness();const { workspace, apiKey, user } = await h.init();+ const { workspaceId, id: projectId } = workspace;const http = new HttpClient({baseUrl: h.baseUrl,@@ -25,40 +24,130 @@ test("update an existing link", async (ctx) => {},});- const { data: link } = await http.post<Link>({- path: "/links",- query: { workspaceId: workspace.workspaceId },- body: {- url,+ afterAll(async () => {+ await h.teardown();+ });++ test("update link", async () => {+ // Update the link with new data+ const { data: link } = await http.post<Link>({+ path: "/links",+ query: { workspaceId },+ body: {+ url,+ domain,+ },+ });++ const newLink = {+ key: nanoid(),+ url: "https://github.com/dubinc/dub",+ expiresAt: new Date("2030-01-01").toISOString(),+ title: "Dub Inc",+ description: "Open-source link management infrastructure.",+ };++ const { data: updatedLink } = await http.put<Link>({+ path: `/links/${link.id}`,+ query: { workspaceId },+ body: newLink,+ });++ expect(updatedLink).toMatchObject({+ ...expectedLink,+ ...newLink,domain,- },+ url: newLink.url,+ userId: user.id,+ projectId,+ workspaceId,+ shortLink: `https://${domain}/${newLink.key}`,+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${newLink.key}?qr=1`,+ tags: [],+ });});- // Update the link- const newLink = {- key: nanoid(),- url: "https://github.com/dubinc/dub",- expiresAt: new Date("2030-01-01").toISOString(),- title: "Dub Inc",- description: "Open-source link management infrastructure.",- };-- const { data: updatedLink } = await http.put<Link>({- path: `/links/${link.id}`,- query: { workspaceId: workspace.workspaceId },- body: newLink,+ // Archive the link+ test("archive link", async () => {+ const { data: link } = await http.post<Link>({+ path: "/links",+ query: { workspaceId },+ body: {+ url,+ domain,+ },+ });++ const { status, data: updatedLink } = await http.put<Link>({+ path: `/links/${link.id}`,+ query: { workspaceId },+ body: {+ archived: true,+ },+ });++ expect(status).toEqual(200);+ expect(updatedLink).toMatchObject({+ ...expectedLink,+ archived: true,+ domain,+ url: link.url,+ userId: user.id,+ projectId,+ workspaceId,+ shortLink: `https://${domain}/${link.key}`,+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,+ tags: [],+ });++ // Fetch the link+ const { data: archivedLink } = await http.get<Link>({+ path: `/links/${link.id}`,+ query: { workspaceId },+ });++ expect(archivedLink.archived).toEqual(true);});- expect(updatedLink).toEqual({- ...expectedLink,- ...newLink,- domain,- url: newLink.url,- userId: user.id,- projectId: workspace.id,- workspaceId: workspace.workspaceId,- shortLink: `https://${domain}/${newLink.key}`,- qrCode: `https://api.dub.co/qr?url=https://${domain}/${newLink.key}?qr=1`,- tags: [],+ // Unarchive the link+ test("unarchive link", async () => {+ const { data: link } = await http.post<Link>({+ path: "/links",+ query: { workspaceId },+ body: {+ url,+ domain,+ },+ });++ const { status, data: updatedLink } = await http.put<Link>({+ path: `/links/${link.id}`,+ query: { workspaceId },+ body: {+ archived: false,+ },+ });++ expect(status).toEqual(200);+ expect(updatedLink).toMatchObject({+ ...expectedLink,+ archived: false,+ domain,+ url: link.url,+ userId: user.id,+ projectId,+ workspaceId,+ shortLink: `https://${domain}/${link.key}`,+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,+ tags: [],+ });++ // Fetch the link+ const { data: unarchivedLink } = await http.get<Link>({+ path: `/links/${link.id}`,+ query: { workspaceId },+ });++ expect(unarchivedLink.archived).toEqual(false);});});