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 metatags retrieval test and environment variables configuration

Kiran K02752a402f59
diff --git a/apps/web/tests/metatags/retrieve-metatags.test.ts b/apps/web/tests/metatags/retrieve-metatags.test.ts
index f1d6ea082e..ba7ec88da3 100644
--- a/apps/web/tests/metatags/retrieve-metatags.test.ts
+++ b/apps/web/tests/metatags/retrieve-metatags.test.ts
@@ -13,15 +13,15 @@ test("GET /metatags", async (ctx) => {
const { status, data: metatags } = await http.get<MetaTag>({
path: `/metatags`,
query: {
- url: "https://dub.co",
+ url: "https://twitter.com",
},
});
expect(status).toEqual(200);
expect(metatags).toStrictEqual({
- title: "Dub.co - Link Management for Modern Marketing Teams",
+ title: "X. It’s what’s happening",
description:
- "Dub.co is the open-source link management infrastructure for modern marketing teams to create, share, and track short links.",
- image: "https://assets.dub.co/thumbnail.jpg",
+ "From breaking news and entertainment to sports and politics, get the full story with all the live commentary.",
+ image: "https://abs.twimg.com/favicons/twitter.3.ico",
});
});
diff --git a/apps/web/tests/utils/env.ts b/apps/web/tests/utils/env.ts
index 0ef35f365d..1c3c23a311 100644
--- a/apps/web/tests/utils/env.ts
+++ b/apps/web/tests/utils/env.ts
@@ -1,7 +1,10 @@
import { z } from "zod";
export const integrationTestEnv = z.object({
- API_BASE_URL: z.string().url().default("http://api.localhost:8888"),
+ API_BASE_URL: z.string().url().default("https://api.dub.co"),
TOKEN: z.string().min(1),
USER_ID: z.string().min(1),
+ WORKSPACE_ID: z.string().min(1).default("ws_clv6iazq2003k8lh32eclix8l"),
+ WORKSPACE_SLUG: z.string().min(1).default("acme"),
+ WORKSPACE_NAME: z.string().min(1).default("Acme"),
});
diff --git a/apps/web/tests/utils/globalSetup.ts b/apps/web/tests/utils/globalSetup.ts
index 37e1bdd357..e69de29bb2 100644
--- a/apps/web/tests/utils/globalSetup.ts
+++ b/apps/web/tests/utils/globalSetup.ts
@@ -1,71 +0,0 @@
-import prisma from "@/lib/prisma";
-import { nanoid } from "@dub/utils";
-import { Project } from "@prisma/client";
-import { HttpClient } from "../utils/http";
-import { integrationTestEnv } from "./env";
-
-const workspaceSlug = `dub-${nanoid()}`;
-let teardownHappened = false;
-
-const { USER_ID, TOKEN, API_BASE_URL } = integrationTestEnv.parse(process.env);
-
-declare module "vitest" {
- export interface ProvidedContext {
- workspace: Project & { workspaceId: string };
- }
-}
-
-export async function setup({ provide }) {
- const http = new HttpClient({
- baseUrl: API_BASE_URL,
- headers: {
- Authorization: `Bearer ${TOKEN}`,
- },
- });
-
- await http.post({
- path: "/workspaces",
- body: { name: "Dub", slug: workspaceSlug },
- });
-
- const workspace = await prisma.project.create({
- data: {
- name: "Dub",
- slug: workspaceSlug,
- plan: "pro",
- inviteCode: nanoid(6),
- billingCycleStart: new Date().getDate(),
- linksLimit: 1000,
- tagsLimit: 1000,
- users: {
- create: {
- userId: USER_ID,
- role: "owner",
- },
- },
- defaultDomains: {
- create: {},
- },
- },
- });
-
- provide("workspace", { ...workspace, workspaceId: `ws_${workspace.id}` });
-}
-
-export async function teardown() {
- if (teardownHappened) {
- throw new Error("teardown called twice");
- }
-
- teardownHappened = true;
-
- // await prisma.$transaction([
- // prisma.project.deleteMany({
- // where: {
- // slug: workspaceSlug,
- // },
- // }),
- // ]);
-
- // await prisma.$disconnect();
-}
diff --git a/apps/web/tests/utils/integration.ts b/apps/web/tests/utils/integration.ts
index 364d32a49f..50c9cc3717 100644
--- a/apps/web/tests/utils/integration.ts
+++ b/apps/web/tests/utils/integration.ts
@@ -1,13 +1,12 @@
-import prisma from "@/lib/prisma";
import { Project, User } from "@prisma/client";
-import { inject, type TaskContext } from "vitest";
+import { type TaskContext } from "vitest";
import { z } from "zod";
import { HttpClient } from "../utils/http";
import { integrationTestEnv } from "./env";
interface Resources {
user: Pick<User, "id">;
- workspace: Project & { workspaceId: string };
+ workspace: Pick<Project, "id" | "slug" | "name"> & { workspaceId: string };
apiKey: { token: string };
}
@@ -32,51 +31,35 @@ export class IntegrationHarness {
}
async init() {
+ const { USER_ID, TOKEN, WORKSPACE_ID, WORKSPACE_SLUG, WORKSPACE_NAME } =
+ this.env;
+
const user = {
- id: this.env.USER_ID,
+ id: USER_ID,
};
const apiKey = {
- token: this.env.TOKEN,
+ token: TOKEN,
};
- const workspace = inject("workspace");
+ const workspace = {
+ id: WORKSPACE_ID,
+ slug: WORKSPACE_SLUG,
+ name: WORKSPACE_NAME,
+ };
this.resources = {
user,
- workspace,
apiKey,
+ workspace: {
+ ...workspace,
+ workspaceId: workspace.id,
+ },
};
return { ...this.resources, http: this.http };
}
- public async teardown() {
- // await prisma.$transaction([
- // prisma.project.deleteMany({
- // where: {
- // users: {
- // some: {
- // userId: this.resources.user.id,
- // },
- // },
- // },
- // }),
- // prisma.user.delete({ where: { id: this.resources.user.id } }),
- // ]);
- // await prisma.$disconnect();
- }
-
- public async cleanup(id: string) {
- console.log("Deleting workspace", id);
-
- await prisma.project.delete({
- where: {
- id,
- },
- });
- }
-
// Delete link
public async deleteLink(id: string) {
const { workspaceId } = this.resources.workspace;
diff --git a/apps/web/vitest.config.ts b/apps/web/vitest.config.ts
index 283bde36a6..a6d76589c0 100644
--- a/apps/web/vitest.config.ts
+++ b/apps/web/vitest.config.ts
@@ -8,6 +8,5 @@ export default defineConfig({
reporters: ["verbose"],
globals: true,
testTimeout: 50000,
- globalSetup: ["./tests/utils/globalSetup.ts"],
},
});