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.

add test for Retrieve the metatags for a URL

Kiran K1520b319c2ea
diff --git a/apps/web/lib/openapi/metatags/index.ts b/apps/web/lib/openapi/metatags/index.ts
index bab1da443d..5ba660f1e5 100644
--- a/apps/web/lib/openapi/metatags/index.ts
+++ b/apps/web/lib/openapi/metatags/index.ts
@@ -1,4 +1,5 @@
import { getUrlQuerySchema } from "@/lib/zod/schemas";
+import { metaTagsSchema } from "@/lib/zod/schemas/metatags";
import { ZodOpenApiOperationObject, ZodOpenApiPathsObject } from "zod-openapi";
const getMetatags: ZodOpenApiOperationObject = {
@@ -14,23 +15,7 @@ const getMetatags: ZodOpenApiOperationObject = {
description: "The retrieved metatags",
content: {
"application/json": {
- schema: {
- type: "object",
- properties: {
- title: {
- type: "string",
- description: "The meta title tag for the URL",
- },
- description: {
- type: "string",
- description: "The meta description tag for the URL",
- },
- image: {
- type: "string",
- description: "The OpenGraph image for the URL",
- },
- },
- },
+ schema: metaTagsSchema,
},
},
},
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 2ba0b91d38..cdde01371d 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -2,6 +2,7 @@ import z from "@/lib/zod";
import { DirectorySyncProviders } from "@boxyhq/saml-jackson";
import { Link } from "@prisma/client";
import { createLinkBodySchema } from "./zod/schemas/links";
+import { metaTagsSchema } from "@/lib/zod/schemas/metatags";
export type LinkProps = Link;
@@ -184,3 +185,5 @@ export const tagColors = [
"pink",
"brown",
] as const;
+
+export type MetaTag = z.infer<typeof metaTagsSchema>;
diff --git a/apps/web/lib/zod/schemas/metatags.ts b/apps/web/lib/zod/schemas/metatags.ts
new file mode 100644
index 0000000000..4e4c6ee534
--- /dev/null
+++ b/apps/web/lib/zod/schemas/metatags.ts
@@ -0,0 +1,10 @@
+import z from "@/lib/zod";
+
+export const metaTagsSchema = z.object({
+ title: z.string().nullable().describe("The meta title tag for the URL"),
+ description: z
+ .string()
+ .nullable()
+ .describe("The meta description tag for the URL"),
+ image: z.string().nullable().describe("The OpenGraph image for the URL"),
+});
\ No newline at end of file
diff --git a/apps/web/tests/metatags/retrieve-metatags.test.ts b/apps/web/tests/metatags/retrieve-metatags.test.ts
new file mode 100644
index 0000000000..72ff90f084
--- /dev/null
+++ b/apps/web/tests/metatags/retrieve-metatags.test.ts
@@ -0,0 +1,27 @@
+import { expect, test } from "vitest";
+import { HttpClient } from "../utils/http";
+import { IntegrationHarness } from "../utils/integration";
+import { MetaTag } from "@/lib/types";
+
+test("retrieve the metatags for a URL", async (ctx) => {
+ const h = new IntegrationHarness(ctx);
+
+ const http = new HttpClient({
+ baseUrl: h.baseUrl,
+ });
+
+ const { status, data: metatags } = await http.get<MetaTag>({
+ path: `/metatags`,
+ query: {
+ url: "https://dub.co",
+ },
+ });
+
+ expect(status).toEqual(200);
+ expect(metatags).toMatchObject({
+ title: "Dub.co - Link Management for Modern Marketing Teams",
+ 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",
+ });
+});
diff --git a/apps/web/tests/utils/integration.ts b/apps/web/tests/utils/integration.ts
index 269f311ab1..316ae09b5c 100644
--- a/apps/web/tests/utils/integration.ts
+++ b/apps/web/tests/utils/integration.ts
@@ -31,7 +31,6 @@ export class IntegrationHarness {
async seed() {
this.ctx.onTestFinished(async () => {
await prisma.$transaction([
- // prisma.token.delete({ where: { id: this.resources.apiKey.id } }),
prisma.project.deleteMany({
where: {
users: {
@@ -41,8 +40,6 @@ export class IntegrationHarness {
},
},
}),
-
- // prisma.project.delete({ where: { id: this.resources.workspace.id } }),
prisma.user.delete({ where: { id: this.resources.user.id } }),
]);