Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix the tests

Kiran Kbbcd3c1e676d
diff --git a/apps/web/app/api/links/upsert/route.ts b/apps/web/app/api/links/upsert/route.ts
index 17d779b2d4..711db002a7 100644
--- a/apps/web/app/api/links/upsert/route.ts
+++ b/apps/web/app/api/links/upsert/route.ts
@@ -1,5 +1,10 @@
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
-import { createLink, processLink, updateLink } from "@/lib/api/links";
+import {
+ createLink,
+ processLink,
+ transformLink,
+ updateLink,
+} from "@/lib/api/links";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import prisma from "@/lib/prisma";
@@ -19,6 +24,19 @@ export const PUT = withWorkspace(
projectId: workspace.id,
url: body.url,
},
+ include: {
+ tags: {
+ select: {
+ tag: {
+ select: {
+ id: true,
+ name: true,
+ color: true,
+ },
+ },
+ },
+ },
+ },
});
if (link) {
@@ -35,7 +53,7 @@ export const PUT = withWorkspace(
// if link and updatedLink are identical, return the link
if (deepEqual(link, updatedLink)) {
- return NextResponse.json(link, { headers });
+ return NextResponse.json(transformLink(link), { headers });
}
if (updatedLink.projectId !== link?.projectId) {
diff --git a/apps/web/lib/openapi/links/index.ts b/apps/web/lib/openapi/links/index.ts
index 9a44f6f5d5..6d174ec688 100644
--- a/apps/web/lib/openapi/links/index.ts
+++ b/apps/web/lib/openapi/links/index.ts
@@ -28,6 +28,6 @@ export const linksPaths: ZodOpenApiPathsObject = {
post: createBulkLink,
},
"/links/upsert": {
- post: upsertLink,
+ put: upsertLink,
},
};
diff --git a/apps/web/tests/links/upsert-link.test.ts b/apps/web/tests/links/upsert-link.test.ts
index 0de3109836..a477563403 100644
--- a/apps/web/tests/links/upsert-link.test.ts
+++ b/apps/web/tests/links/upsert-link.test.ts
@@ -1,5 +1,5 @@
import { Link } from "@prisma/client";
-import { describe, expect, test } from "vitest";
+import { afterAll, describe, expect, test } from "vitest";
import { randomId } from "../utils/helpers";
import { IntegrationHarness } from "../utils/integration";
import { link } from "../utils/resource";
@@ -16,13 +16,19 @@ describe.sequential("PUT /links/upsert", async () => {
let createdLink: Link;
+ afterAll(async () => {
+ await h.deleteLink(createdLink.id);
+ });
+
test("New link", async () => {
- const { data: createdLink } = await http.put<Link>({
+ const { data } = await http.put<Link>({
path: "/links/upsert",
query: { workspaceId },
body: { domain, url },
});
+ createdLink = data;
+
expect(createdLink).toStrictEqual({
...expectedLink,
domain,
@@ -34,8 +40,6 @@ describe.sequential("PUT /links/upsert", async () => {
qrCode: `https://api.dub.co/qr?url=https://${domain}/${createdLink.key}?qr=1`,
tags: [],
});
-
- await h.deleteLink(createdLink.id);
});
test("Existing link", async () => {
@@ -45,6 +49,16 @@ describe.sequential("PUT /links/upsert", async () => {
body: { domain, url },
});
- expect(updatedLink).toStrictEqual(createdLink);
+ expect(updatedLink).toStrictEqual({
+ ...expectedLink,
+ domain,
+ url,
+ userId: user.id,
+ projectId,
+ workspaceId,
+ shortLink: `https://${domain}/${createdLink.key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${createdLink.key}?qr=1`,
+ tags: [],
+ });
});
});