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 the tests

Kiran K10499d42762c
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index 4f45482de0..c8170a6d39 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -14,6 +14,8 @@ describe.sequential("POST /links", async () => {
const projectId = workspaceId.replace("ws_", "");
test("default domain", async () => {
+ const externalId = randomId();
+
const { status, data: link } = await http.post<Link>({
path: "/links",
query: { workspaceId },
@@ -23,6 +25,7 @@ describe.sequential("POST /links", async () => {
comments: "This is a test",
rewrite: true,
domain,
+ externalId,
},
});
@@ -30,6 +33,7 @@ describe.sequential("POST /links", async () => {
expect(link).toStrictEqual({
...expectedLink,
url,
+ externalId,
publicStats: true,
comments: "This is a test",
rewrite: true,
diff --git a/apps/web/tests/links/retrieve-link.test.ts b/apps/web/tests/links/retrieve-link.test.ts
index f0db10e56c..1a550e4ad0 100644
--- a/apps/web/tests/links/retrieve-link.test.ts
+++ b/apps/web/tests/links/retrieve-link.test.ts
@@ -1,56 +1,83 @@
import { Link } from "@prisma/client";
import { expectedLink } from "tests/utils/schema";
-import { 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";
const { domain, url } = link;
-test("GET /links/info", async (ctx) => {
- const h = new IntegrationHarness(ctx);
+describe.sequential("GET /links/**", async () => {
+ const h = new IntegrationHarness();
const { workspace, http, user } = await h.init();
const { workspaceId } = workspace;
const projectId = workspaceId.replace("ws_", "");
+ const externalId = randomId();
+ const key = randomId();
- const newLink: Partial<Link> = {
- url,
- domain,
- key: randomId(),
- archived: true,
- publicStats: true,
- comments: "This is a test",
- 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`,
- },
- title: "custom title",
- description: "custom description",
- };
-
- const { status, data: link } = await http.post<Link>({
+ const { data: newLink } = await http.post<Link>({
path: "/links",
query: { workspaceId },
- body: { ...newLink, prefix: "prefix" },
+ body: {
+ url,
+ domain,
+ key,
+ externalId,
+ },
});
- expect(status).toEqual(200);
- expect(link).toStrictEqual({
- ...expectedLink,
- ...newLink,
- projectId,
- workspaceId,
- userId: user.id,
- expiresAt: "2030-04-16T17:00:00.000Z",
- shortLink: `https://${domain}/${newLink.key}`,
- qrCode: `https://api.dub.co/qr?url=https://${domain}/${newLink.key}?qr=1`,
- tags: [],
+ afterAll(async () => {
+ await h.deleteLink(newLink.id);
+ });
+
+ test("by domain and key", async () => {
+ const { status, data: link } = await http.get<Link>({
+ path: "/links/info",
+ query: { workspaceId, domain, key },
+ });
+
+ expect(status).toEqual(200);
+ expect(link).toStrictEqual({
+ ...expectedLink,
+ ...link,
+ projectId,
+ workspaceId,
+ userId: user.id,
+ shortLink: `https://${domain}/${key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${key}?qr=1`,
+ tags: [],
+ });
});
- await h.deleteLink(link.id);
+ test("by linkId", async () => {
+ const { status, data: link } = await http.get<Link>({
+ path: `/links/${newLink.id}`,
+ query: { workspaceId },
+ });
+
+ expect(status).toEqual(200);
+ expect(link).toStrictEqual({
+ ...expectedLink,
+ ...link,
+ projectId,
+ userId: user.id,
+ tags: [],
+ });
+ });
+
+ test("by externalId", async () => {
+ const { status, data: link } = await http.get<Link>({
+ path: `/links/ext_${externalId}`,
+ query: { workspaceId },
+ });
+
+ expect(status).toEqual(200);
+ expect(link).toStrictEqual({
+ ...expectedLink,
+ ...link,
+ projectId,
+ userId: user.id,
+ tags: [],
+ });
+ });
});