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 creating a link with an invalid expiration date and updating an existing link
Kiran K67774611e7e4
diff --git a/apps/web/tests/links/create-link-error.test.ts b/apps/web/tests/links/create-link-error.test.tsindex 1ee4827faf..203189486e 100644--- a/apps/web/tests/links/create-link-error.test.ts+++ b/apps/web/tests/links/create-link-error.test.ts@@ -61,6 +61,25 @@ const cases = [},},},+ {+ name: "create link with invalid expiration date",+ body: {+ domain,+ url,+ expiresAt: new Date("2020-01-01").toISOString(),+ },+ expected: {+ status: 422,+ data: {+ error: {+ code: "unprocessable_entity",+ message: "custom: expiresAt: Expiry date must be in the future.",+ doc_url:+ "https://dub.co/docs/api-reference/errors#unprocessable_entity",+ },+ },+ },+ },];cases.forEach(({ name, body, expected }) => {diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.tsnew file mode 100644index 0000000000..e97742c20e--- /dev/null+++ b/apps/web/tests/links/update-link.test.ts@@ -0,0 +1,58 @@+import { expect, test } from "vitest";+import { HttpClient } from "../utils/http";+import { Link } from "@prisma/client";+import { IntegrationHarness } from "../utils/integration";+import { expectedLink } from "../utils/schema";+import { nanoid } from "@dub/utils";++test("update an existing link", async (ctx) => {+ const h = new IntegrationHarness(ctx);+ const { workspace, apiKey, user } = await h.init();++ const http = new HttpClient({+ baseUrl: h.baseUrl,+ headers: {+ Authorization: `Bearer ${apiKey.token}`,+ },+ });++ const domain = "dub.sh";+ const url = "https://github.com/dubinc";++ const { data: link } = await http.post<Link>({+ path: "/links",+ query: { workspaceId: workspace.workspaceId },+ body: {+ url,+ domain,+ },+ });++ // 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,+ });++ 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}`,+ tags: [],+ });+});