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.

Refactor link tests and add expectedLink schema

Kiran Kde255b2323e3
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index a83792637a..e5910d837c 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -2,6 +2,7 @@ import { expect, test } from "vitest";
import { HttpClient } from "../utils/http";
import { Link } from "@prisma/client";
import { IntegrationHarness } from "../utils/integration";
+import { expectedLink } from "../utils/schema";
test("creates new link", async (ctx) => {
const h = new IntegrationHarness(ctx);
@@ -28,39 +29,14 @@ test("creates new link", async (ctx) => {
expect(status).toEqual(200);
expect(link).toEqual({
- id: expect.any(String),
+ ...expectedLink,
domain,
url,
- key: expect.any(String),
userId: user.id,
projectId: workspace.id,
workspaceId: workspace.workspaceId,
- archived: false,
- expiresAt: null,
- password: null,
- proxy: false,
- title: null,
- description: null,
- image: null,
- utm_source: null,
- utm_medium: null,
- utm_campaign: null,
- utm_term: null,
- utm_content: null,
- rewrite: false,
- ios: null,
- android: null,
- geo: null,
- publicStats: false,
- clicks: 0,
- lastClicked: null,
- checkDisabled: false,
- tagId: null,
- comments: null,
- tags: [],
- createdAt: expect.any(String),
- updatedAt: expect.any(String),
shortLink: `https://${domain}/${link.key}`,
qrCode: `https://api.dub.co/qr?url=https://${domain}/${link.key}`,
+ tags: [],
});
});
diff --git a/apps/web/tests/links/list-links.test.ts b/apps/web/tests/links/list-links.test.ts
index afd78bd2b0..a747f656a4 100644
--- a/apps/web/tests/links/list-links.test.ts
+++ b/apps/web/tests/links/list-links.test.ts
@@ -2,6 +2,7 @@ import { expect, test } from "vitest";
import { HttpClient } from "../utils/http";
import { Link } from "@prisma/client";
import { IntegrationHarness } from "../utils/integration";
+import { expectedLink } from "../utils/schema";
test("list links", async (ctx) => {
const h = new IntegrationHarness(ctx);
@@ -42,79 +43,32 @@ test("list links", async (ctx) => {
expect(status).toEqual(200);
expect(links.length).toEqual(2);
- expect(links[0]).toEqual({
- id: expect.any(String),
- domain,
- url,
- key: expect.any(String),
- userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
- archived: false,
- expiresAt: null,
- password: null,
- proxy: false,
- title: null,
- description: null,
- image: null,
- utm_source: null,
- utm_medium: null,
- utm_campaign: null,
- utm_term: null,
- utm_content: null,
- rewrite: false,
- ios: null,
- android: null,
- geo: null,
- publicStats: false,
- clicks: 0,
- lastClicked: null,
- checkDisabled: false,
- tagId: null,
- comments: null,
- tags: [],
- createdAt: expect.any(String),
- updatedAt: expect.any(String),
- shortLink: `https://${domain}/${secondLink.key}`,
- qrCode: `https://api.dub.co/qr?url=https://${domain}/${secondLink.key}`,
- user: JSON.parse(JSON.stringify(user)),
- });
-
- expect(links[1]).toEqual({
- id: expect.any(String),
- domain,
- url,
- key: expect.any(String),
- userId: user.id,
- projectId: workspace.id,
- workspaceId: workspace.workspaceId,
- archived: false,
- expiresAt: null,
- password: null,
- proxy: false,
- title: null,
- description: null,
- image: null,
- utm_source: null,
- utm_medium: null,
- utm_campaign: null,
- utm_term: null,
- utm_content: null,
- rewrite: false,
- ios: null,
- android: null,
- geo: null,
- publicStats: false,
- clicks: 0,
- lastClicked: null,
- checkDisabled: false,
- tagId: null,
- comments: null,
- tags: [],
- createdAt: expect.any(String),
- updatedAt: expect.any(String),
- shortLink: `https://${domain}/${firstLink.key}`,
- qrCode: `https://api.dub.co/qr?url=https://${domain}/${firstLink.key}`,
- user: JSON.parse(JSON.stringify(user)),
- });
+ expect(links).toEqual(
+ [
+ {
+ ...expectedLink,
+ domain,
+ url,
+ userId: user.id,
+ projectId: workspace.id,
+ workspaceId: workspace.workspaceId,
+ tags: [],
+ shortLink: `https://${domain}/${secondLink.key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${secondLink.key}`,
+ user: JSON.parse(JSON.stringify(user)),
+ },
+ {
+ ...expectedLink,
+ domain,
+ url,
+ userId: user.id,
+ projectId: workspace.id,
+ workspaceId: workspace.workspaceId,
+ tags: [],
+ shortLink: `https://${domain}/${firstLink.key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${domain}/${firstLink.key}`,
+ user: JSON.parse(JSON.stringify(user)),
+ },
+ ],
+ );
});
diff --git a/apps/web/tests/utils/schema.ts b/apps/web/tests/utils/schema.ts
new file mode 100644
index 0000000000..2595d00802
--- /dev/null
+++ b/apps/web/tests/utils/schema.ts
@@ -0,0 +1,32 @@
+import { TagProps } from "@/lib/types";
+import { Link } from "@prisma/client";
+import { expect, test } from "vitest";
+
+export const expectedLink: Partial<Link> = {
+ id: expect.any(String),
+ key: expect.any(String),
+ archived: false,
+ expiresAt: null,
+ password: null,
+ proxy: false,
+ title: null,
+ description: null,
+ image: null,
+ utm_source: null,
+ utm_medium: null,
+ utm_campaign: null,
+ utm_term: null,
+ utm_content: null,
+ rewrite: false,
+ ios: null,
+ android: null,
+ geo: null,
+ publicStats: false,
+ clicks: 0,
+ lastClicked: null,
+ checkDisabled: false,
+ tagId: null,
+ comments: null,
+ createdAt: expect.any(String),
+ updatedAt: expect.any(String),
+};