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 test descriptions to match API endpoints

Kiran Kcd07dc69540f
diff --git a/apps/web/tests/links/bulk-create-link.test.ts b/apps/web/tests/links/bulk-create-link.test.ts
new file mode 100644
index 0000000000..7c9fe413e9
--- /dev/null
+++ b/apps/web/tests/links/bulk-create-link.test.ts
@@ -0,0 +1,31 @@
+import { nanoid } from "@dub/utils";
+import { Link } from "@prisma/client";
+import { expect, test } from "vitest";
+import { HttpClient } from "../utils/http";
+import { IntegrationHarness } from "../utils/integration";
+
+test("POST /links/bulk", 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 bulkLinks = Array.from({ length: 10 }, () => ({
+ url: `https://example.com/${nanoid()}`,
+ }));
+
+ const { status, data: links } = await http.post<Link>({
+ path: "/links/bulk",
+ query: { workspaceId },
+ body: bulkLinks,
+ });
+
+ expect(status).toEqual(200);
+ expect(links).toHaveLength(10);
+});
diff --git a/apps/web/tests/links/count-links.test.ts b/apps/web/tests/links/count-links.test.ts
new file mode 100644
index 0000000000..eecb0a8634
--- /dev/null
+++ b/apps/web/tests/links/count-links.test.ts
@@ -0,0 +1,41 @@
+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("GET /links/count", 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}`,
+ },
+ });
+
+ await Promise.all([
+ http.post<Link>({
+ path: "/links",
+ query: { workspaceId },
+ body: { url, domain },
+ }),
+ http.post<Link>({
+ path: "/links",
+ query: { workspaceId },
+ body: { url, domain },
+ }),
+ ]);
+
+ const { status, data: count } = await http.get<Link[]>({
+ path: "/links/count",
+ query: { workspaceId },
+ });
+
+ expect(status).toEqual(200);
+ expect(count).toEqual(2);
+});
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index ca18617877..f7b8818157 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -8,16 +8,10 @@ import { link } from "../utils/resource";
const { domain, url } = link;
-// TODO: Move this to shared
-// userId: user.id,
-// projectId: workspace.id,
-// workspaceId: workspace.workspaceId,
-// shortLink: `https://${domain}/${link.key}`,
-// qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
-
-describe("create a link with", async () => {
+describe("POST /links", async () => {
const h = new IntegrationHarness();
const { workspace, apiKey, user } = await h.init();
+ const { workspaceId, id: projectId } = workspace;
const http = new HttpClient({
baseUrl: h.baseUrl,
@@ -30,10 +24,10 @@ describe("create a link with", async () => {
await h.teardown();
});
- test("default domain", async (ctx) => {
+ test("default domain", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
},
@@ -44,8 +38,8 @@ describe("create a link with", async () => {
...expectedLink,
url,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: [],
@@ -58,7 +52,7 @@ describe("create a link with", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
key,
@@ -73,8 +67,8 @@ describe("create a link with", async () => {
url,
comments,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${key}?qr=1`,
tags: [],
@@ -89,7 +83,7 @@ describe("create a link with", async () => {
Link & { shortLink: string }
>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
domain,
@@ -104,8 +98,8 @@ describe("create a link with", async () => {
domain,
url,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: [],
@@ -128,7 +122,7 @@ describe("create a link with", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url: longUrl.href,
},
@@ -140,8 +134,8 @@ describe("create a link with", async () => {
...utm,
url: longUrl.href,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: [],
@@ -153,7 +147,7 @@ describe("create a link with", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
password,
@@ -166,8 +160,8 @@ describe("create a link with", async () => {
url,
password,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: [],
@@ -180,7 +174,7 @@ describe("create a link with", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
expiresAt,
@@ -195,8 +189,8 @@ describe("create a link with", async () => {
expiresAt: "2030-04-16T11:30:00.000Z",
expiredUrl,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: [],
@@ -210,7 +204,7 @@ describe("create a link with", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
ios,
@@ -225,8 +219,8 @@ describe("create a link with", async () => {
ios,
android,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: [],
@@ -242,7 +236,7 @@ describe("create a link with", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
geo,
@@ -255,8 +249,8 @@ describe("create a link with", async () => {
url,
geo,
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: [],
@@ -273,7 +267,7 @@ describe("create a link with", async () => {
tagsToCreate.map(({ tag, color }) =>
http.post<Tag>({
path: "/tags",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: { tag, color },
}),
),
@@ -290,7 +284,7 @@ describe("create a link with", async () => {
const { status, data: link } = await http.post<Link & { tags: [] }>({
path: "/links",
- query: { workspaceId: workspace.workspaceId },
+ query: { workspaceId },
body: {
url,
tagIds,
@@ -304,8 +298,8 @@ describe("create a link with", async () => {
url,
tagId: expect.any(String), // TODO: Fix this
userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
+ projectId,
+ workspaceId,
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}?qr=1`,
tags: expect.arrayContaining(tags),
diff --git a/apps/web/tests/links/delete-link.test.ts b/apps/web/tests/links/delete-link.test.ts
index 2ddce6404f..b012030bfd 100644
--- a/apps/web/tests/links/delete-link.test.ts
+++ b/apps/web/tests/links/delete-link.test.ts
@@ -6,7 +6,7 @@ import { link } from "../utils/resource";
const { domain, url } = link;
-test("delete an existing link", async (ctx) => {
+test("DELETE /links/{linkId}", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, apiKey } = await h.init();
const { workspaceId } = workspace;
diff --git a/apps/web/tests/links/list-links.test.ts b/apps/web/tests/links/list-links.test.ts
index 07a29c11ec..a92038f1d6 100644
--- a/apps/web/tests/links/list-links.test.ts
+++ b/apps/web/tests/links/list-links.test.ts
@@ -7,7 +7,7 @@ import { link } from "../utils/resource";
const { domain, url } = link;
-test("list links", async (ctx) => {
+test("GET /links", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, apiKey, user } = await h.init();
const { workspaceId, id: projectId } = workspace;
diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.ts
index a0994f7d02..adc8a7c908 100644
--- a/apps/web/tests/links/update-link.test.ts
+++ b/apps/web/tests/links/update-link.test.ts
@@ -9,10 +9,10 @@ import { link } from "../utils/resource";
const { domain, url } = link;
// TODO:
-// Update other fields
+// Make sure we cover all the fields
// Add/update/delete tags
-describe("PUT - /links/{linkId}", async () => {
+describe("PUT /links/{linkId}", async () => {
const h = new IntegrationHarness();
const { workspace, apiKey, user } = await h.init();
const { workspaceId, id: projectId } = workspace;
@@ -39,12 +39,22 @@ describe("PUT - /links/{linkId}", async () => {
},
});
- const newLink = {
+ const newLink: Partial<Link> = {
key: nanoid(),
url: "https://github.com/dubinc/dub",
- expiresAt: new Date("2030-01-01").toISOString(),
title: "Dub Inc",
description: "Open-source link management infrastructure.",
+ publicStats: true,
+ comments: "This is a comment.",
+ expiresAt: new Date("2030-04-16 23:59:59"),
+ 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`,
+ },
};
const { data: updatedLink } = await http.put<Link>({
@@ -56,15 +66,28 @@ describe("PUT - /links/{linkId}", async () => {
expect(updatedLink).toMatchObject({
...expectedLink,
...newLink,
+ expiresAt: "2030-04-16T18:29:59.000Z",
domain,
- url: newLink.url,
- userId: user.id,
projectId,
workspaceId,
+ userId: user.id,
shortLink: `https://${domain}/${newLink.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${newLink.key}?qr=1`,
tags: [],
});
+
+ // Fetch the link
+ const { data: fetchedLink } = await http.get<Link>({
+ path: `/links/${link.id}`,
+ query: { workspaceId },
+ });
+
+ expect({
+ ...fetchedLink,
+ workspaceId,
+ shortLink: `https://${domain}/${newLink.key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${newLink.key}?qr=1`,
+ }).toMatchObject(updatedLink);
});
// Archive the link
diff --git a/apps/web/tests/metatags/retrieve-metatags.test.ts b/apps/web/tests/metatags/retrieve-metatags.test.ts
index 35d733b95f..d917d9d4b8 100644
--- a/apps/web/tests/metatags/retrieve-metatags.test.ts
+++ b/apps/web/tests/metatags/retrieve-metatags.test.ts
@@ -3,7 +3,7 @@ import { expect, test } from "vitest";
import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
-test("retrieve the metatags for a URL", async (ctx) => {
+test("GET /metatags", async (ctx) => {
const h = new IntegrationHarness(ctx);
const http = new HttpClient({
diff --git a/apps/web/tests/tags/create-tag.test.ts b/apps/web/tests/tags/create-tag.test.ts
index d5fb5fa44e..55958a8544 100644
--- a/apps/web/tests/tags/create-tag.test.ts
+++ b/apps/web/tests/tags/create-tag.test.ts
@@ -4,7 +4,7 @@ import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
import { expectedTag } from "../utils/schema";
-test("create a new tag", async (ctx) => {
+test("POST /tags", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, apiKey } = await h.init();
diff --git a/apps/web/tests/tags/list-tags.test.ts b/apps/web/tests/tags/list-tags.test.ts
index 9f6278bb30..6e7cdea058 100644
--- a/apps/web/tests/tags/list-tags.test.ts
+++ b/apps/web/tests/tags/list-tags.test.ts
@@ -3,7 +3,7 @@ import { expect, test } from "vitest";
import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
-test("retrieve list of tags", async (ctx) => {
+test("GET /tags", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, apiKey } = await h.init();
diff --git a/apps/web/tests/workspaces/create-workspace.test.ts b/apps/web/tests/workspaces/create-workspace.test.ts
index 5cbe8e2150..1c0599d806 100644
--- a/apps/web/tests/workspaces/create-workspace.test.ts
+++ b/apps/web/tests/workspaces/create-workspace.test.ts
@@ -6,7 +6,7 @@ import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
import { expectedWorkspace } from "../utils/schema";
-test("creates new workspace", async (ctx) => {
+test("POST /workspaces", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { apiKey } = await h.init();
diff --git a/apps/web/tests/workspaces/list-workspaces.test.ts b/apps/web/tests/workspaces/list-workspaces.test.ts
index 4172bd7ccb..cb90e4e5cb 100644
--- a/apps/web/tests/workspaces/list-workspaces.test.ts
+++ b/apps/web/tests/workspaces/list-workspaces.test.ts
@@ -6,7 +6,7 @@ import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
import { expectedWorkspace } from "../utils/schema";
-test("retrieve list of workspaces", async (ctx) => {
+test("GET /workspaces", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { apiKey, workspace } = await h.init();
diff --git a/apps/web/tests/workspaces/retrieve-workspace.test.ts b/apps/web/tests/workspaces/retrieve-workspace.test.ts
index 215cc611a8..111c0775f8 100644
--- a/apps/web/tests/workspaces/retrieve-workspace.test.ts
+++ b/apps/web/tests/workspaces/retrieve-workspace.test.ts
@@ -4,7 +4,7 @@ import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
import { expectedWorkspace } from "../utils/schema";
-test("retrieve a workspace by id", async (ctx) => {
+test("GET /workspaces/{id}", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, apiKey } = await h.init();
@@ -31,7 +31,7 @@ test("retrieve a workspace by id", async (ctx) => {
});
});
-test("retrieve a workspace by slug", async (ctx) => {
+test("GET /workspaces/{slug}", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, apiKey } = await h.init();