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.

Update update-link.test.ts

Steven Teye392c5ed40cb
diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.ts
index af5822b5d6..42b18a24a5 100644
--- a/apps/web/tests/links/update-link.test.ts
+++ b/apps/web/tests/links/update-link.test.ts
@@ -7,7 +7,7 @@ import { expectedLink } from "../utils/schema";
const { domain, url } = link;
-describe.sequential("PUT /links/{linkId}", async () => {
+describe.sequential("PATCH /links/{linkId}", async () => {
const h = new IntegrationHarness();
const { workspace, http, user } = await h.init();
const { workspaceId } = workspace;
@@ -87,20 +87,26 @@ describe.sequential("PUT /links/{linkId}", async () => {
});
});
- test("update link using PUT (backwards compatibility)", async () => {
- const { data: updatedLink } = await http.put<Link>({
- path: `/links/${link.id}`,
+ // Update the link using externalId
+ test("update link using externalId", async () => {
+ const { status, data: updatedLink } = await http.patch<Link>({
+ path: `/links/ext_${externalId}`,
query: { workspaceId },
- body: { ...toUpdate },
+ body: {
+ url: "https://github.com/dubinc",
+ },
});
+ expect(status).toEqual(200);
expect(updatedLink).toStrictEqual({
...expectedLink,
...toUpdate,
domain,
workspaceId,
externalId,
+ archived: false,
userId: user.id,
+ url: "https://github.com/dubinc",
expiresAt: "2030-04-16T17:00:00.000Z",
projectId: workspaceId.replace("ws_", ""),
shortLink: `https://${domain}/${toUpdate.key}`,
@@ -109,24 +115,12 @@ describe.sequential("PUT /links/{linkId}", async () => {
});
// Fetch the link
- const { data: fetchedLink } = await http.get<Link>({
- path: `/links/${link.id}`,
+ const { data: linkUpdated } = await http.get<Link>({
+ path: `/links/ext_${externalId}`,
query: { workspaceId },
});
- expect(fetchedLink).toStrictEqual({
- ...expectedLink,
- ...toUpdate,
- domain,
- workspaceId,
- externalId,
- userId: user.id,
- expiresAt: "2030-04-16T17:00:00.000Z",
- projectId: workspaceId.replace("ws_", ""),
- shortLink: `https://${domain}/${toUpdate.key}`,
- qrCode: `https://api.dub.co/qr?url=https://${domain}/${toUpdate.key}?qr=1`,
- tags: [],
- });
+ expect(linkUpdated.url).toEqual("https://github.com/dubinc");
});
// Archive the link
@@ -198,40 +192,88 @@ describe.sequential("PUT /links/{linkId}", async () => {
expect(unarchivedLink.archived).toEqual(false);
});
+});
- // Update the link using externalId
- test("update link using externalId", async () => {
- const { status, data: updatedLink } = await http.patch<Link>({
- path: `/links/ext_${externalId}`,
+describe.sequential(
+ "PUT /links/{linkId} (backwards compatibility)",
+ async () => {
+ const h = new IntegrationHarness();
+ const { workspace, http, user } = await h.init();
+ const { workspaceId } = workspace;
+ const externalId = randomId();
+
+ const { data: link } = await http.post<Link>({
+ path: "/links",
query: { workspaceId },
body: {
- url: "https://github.com/dubinc",
+ url,
+ domain,
+ externalId,
},
});
- expect(status).toEqual(200);
- expect(updatedLink).toStrictEqual({
- ...expectedLink,
- ...toUpdate,
- domain,
- workspaceId,
- externalId,
- archived: false,
- userId: user.id,
- url: "https://github.com/dubinc",
- expiresAt: "2030-04-16T17:00:00.000Z",
- projectId: workspaceId.replace("ws_", ""),
- shortLink: `https://${domain}/${toUpdate.key}`,
- qrCode: `https://api.dub.co/qr?url=https://${domain}/${toUpdate.key}?qr=1`,
- tags: [],
- });
+ const toUpdate: Partial<Link> = {
+ key: randomId(),
+ url: "https://github.com/dubinc/dub",
+ title: "Dub Inc",
+ description: "Open-source link management infrastructure.",
+ publicStats: true,
+ comments: "This is a comment.",
+ expiresAt: new Date("2030-04-16T17:00:00.000Z"),
+ expiredUrl: "https://github.com/expired",
+ password: "link-password",
+ ios: "https://apps.apple.com/app/1611158928",
+ android:
+ "https://play.google.com/store/apps/details?id=com.disney.disneyplus",
+ geo: {
+ AF: `${url}/AF`,
+ },
+ };
- // Fetch the link
- const { data: linkUpdated } = await http.get<Link>({
- path: `/links/ext_${externalId}`,
- query: { workspaceId },
+ afterAll(async () => {
+ await h.deleteLink(link.id);
});
- expect(linkUpdated.url).toEqual("https://github.com/dubinc");
- });
-});
+ test("update link using PUT", async () => {
+ const { data: updatedLink } = await http.put<Link>({
+ path: `/links/${link.id}`,
+ query: { workspaceId },
+ body: { ...toUpdate },
+ });
+
+ expect(updatedLink).toStrictEqual({
+ ...expectedLink,
+ ...toUpdate,
+ domain,
+ workspaceId,
+ externalId,
+ userId: user.id,
+ expiresAt: "2030-04-16T17:00:00.000Z",
+ projectId: workspaceId.replace("ws_", ""),
+ shortLink: `https://${domain}/${toUpdate.key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${toUpdate.key}?qr=1`,
+ tags: [],
+ });
+
+ // Fetch the link
+ const { data: fetchedLink } = await http.get<Link>({
+ path: `/links/${link.id}`,
+ query: { workspaceId },
+ });
+
+ expect(fetchedLink).toStrictEqual({
+ ...expectedLink,
+ ...toUpdate,
+ domain,
+ workspaceId,
+ externalId,
+ userId: user.id,
+ expiresAt: "2030-04-16T17:00:00.000Z",
+ projectId: workspaceId.replace("ws_", ""),
+ shortLink: `https://${domain}/${toUpdate.key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${toUpdate.key}?qr=1`,
+ tags: [],
+ });
+ });
+ },
+);