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.

improve the tests

Kiran K460a396e0847
diff --git a/apps/web/tests/links/count-links.test.ts b/apps/web/tests/links/count-links.test.ts
index 3d0a3be01c..2286cb3763 100644
--- a/apps/web/tests/links/count-links.test.ts
+++ b/apps/web/tests/links/count-links.test.ts
@@ -1,5 +1,5 @@
import { Link } from "@prisma/client";
-import { expect, test } from "vitest";
+import { afterAll, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
import { link } from "../utils/resource";
@@ -24,7 +24,9 @@ test("GET /links/count", async (ctx) => {
expect(count).toBeDefined();
expect(count).greaterThanOrEqual(1);
- await h.deleteLink(firstLink.id);
+ afterAll(async () => {
+ await h.deleteLink(firstLink.id);
+ });
// TODO:
// Assert actual value of count
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index fae0594df8..c28e55760e 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -1,7 +1,7 @@
import { LinkSchema } from "@/lib/zod/schemas/links";
import { Link, Tag } from "@prisma/client";
import { IntegrationHarnessOld } from "tests/utils/integration-old";
-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";
@@ -75,7 +75,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("user defined key", async () => {
@@ -104,7 +106,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("prefix", async () => {
@@ -136,7 +140,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("utm builder", async (ctx) => {
@@ -175,7 +181,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("password protection", async () => {
@@ -204,7 +212,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("link expiration", async () => {
@@ -236,7 +246,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("device targeting", async () => {
@@ -269,7 +281,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("geo targeting", async () => {
@@ -302,7 +316,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
test("tags", async () => {
@@ -353,10 +369,12 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await Promise.all([
- ...tagIds.map((id) => h.deleteTag(id)),
- h.deleteLink(link.id),
- ]);
+ afterAll(async () => {
+ await Promise.all([
+ ...tagIds.map((id) => h.deleteTag(id)),
+ h.deleteLink(link.id),
+ ]);
+ });
});
test("custom social media cards", async () => {
@@ -388,7 +406,9 @@ describe.sequential("POST /links", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
});
@@ -420,6 +440,8 @@ describe.sequential("POST /links?workspaceId=xxx", async () => {
});
expect(LinkSchema.strict().parse(link)).toBeTruthy();
- await h.deleteLink(link.id);
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
});
});
diff --git a/apps/web/tests/links/list-links.test.ts b/apps/web/tests/links/list-links.test.ts
index 79e2871e23..d3cacf548f 100644
--- a/apps/web/tests/links/list-links.test.ts
+++ b/apps/web/tests/links/list-links.test.ts
@@ -1,5 +1,5 @@
import { Link } from "@prisma/client";
-import { expect, test } from "vitest";
+import { afterAll, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
import { link } from "../utils/resource";
@@ -36,5 +36,7 @@ test("GET /links", async (ctx) => {
qrCode: `https://api.dub.co/qr?url=https://${domain}/${firstLink.key}?qr=1`,
});
- await h.deleteLink(firstLink.id);
+ afterAll(async () => {
+ await h.deleteLink(firstLink.id);
+ });
});