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 tests for creating and listing tags

Kiran Kb4db8de22e05
diff --git a/apps/web/tests/tags/create-tag.test.ts b/apps/web/tests/tags/create-tag.test.ts
new file mode 100644
index 0000000000..4abf43a3f6
--- /dev/null
+++ b/apps/web/tests/tags/create-tag.test.ts
@@ -0,0 +1,34 @@
+import { expect, test } from "vitest";
+import { HttpClient } from "../utils/http";
+import { Tag } from "@prisma/client";
+import { IntegrationHarness } from "../utils/integration";
+import { expectedTag } from "../utils/schema";
+
+test("create a new tag", async (ctx) => {
+ const h = new IntegrationHarness(ctx);
+ const { workspace, apiKey } = await h.init();
+
+ const http = new HttpClient({
+ baseUrl: h.baseUrl,
+ headers: {
+ Authorization: `Bearer ${apiKey.token}`,
+ },
+ });
+
+ const { status, data: tag } = await http.post<Tag>({
+ path: "/tags",
+ query: { workspaceId: workspace.workspaceId },
+ body: {
+ tag: "news",
+ color: "red",
+ },
+ });
+
+ expect(status).toEqual(201);
+ expect(tag).toEqual({
+ ...expectedTag,
+ name: "news",
+ color: "red",
+ projectId: workspace.id,
+ });
+});
diff --git a/apps/web/tests/tags/list-tags.test.ts b/apps/web/tests/tags/list-tags.test.ts
new file mode 100644
index 0000000000..bdb95f82d8
--- /dev/null
+++ b/apps/web/tests/tags/list-tags.test.ts
@@ -0,0 +1,49 @@
+import { expect, test } from "vitest";
+import { HttpClient } from "../utils/http";
+import { Tag } from "@prisma/client";
+import { IntegrationHarness } from "../utils/integration";
+
+test("retrieve list of tags", async (ctx) => {
+ const h = new IntegrationHarness(ctx);
+ const { workspace, apiKey } = await h.init();
+
+ const http = new HttpClient({
+ baseUrl: h.baseUrl,
+ headers: {
+ Authorization: `Bearer ${apiKey.token}`,
+ },
+ });
+
+ const tagsToCreate = [
+ { tag: "news", color: "red" },
+ { tag: "work", color: "green" },
+ ];
+
+ for (const { tag, color } of tagsToCreate) {
+ await http.post<Tag>({
+ path: "/tags",
+ query: { workspaceId: workspace.workspaceId },
+ body: { tag, color },
+ });
+ }
+
+ // Fetch the list of tags
+ const { status, data: tags } = await http.get<Tag[]>({
+ path: "/tags",
+ query: { workspaceId: workspace.workspaceId },
+ });
+
+ expect(status).toEqual(200);
+ expect(tags).toEqual([
+ {
+ id: expect.any(String),
+ name: "news",
+ color: "red",
+ },
+ {
+ id: expect.any(String),
+ name: "work",
+ color: "green",
+ },
+ ]);
+});
diff --git a/apps/web/tests/utils/schema.ts b/apps/web/tests/utils/schema.ts
index 2595d00802..1717a19266 100644
--- a/apps/web/tests/utils/schema.ts
+++ b/apps/web/tests/utils/schema.ts
@@ -1,6 +1,5 @@
-import { TagProps } from "@/lib/types";
-import { Link } from "@prisma/client";
-import { expect, test } from "vitest";
+import { Link, Tag } from "@prisma/client";
+import { expect } from "vitest";
export const expectedLink: Partial<Link> = {
id: expect.any(String),
@@ -30,3 +29,9 @@ export const expectedLink: Partial<Link> = {
createdAt: expect.any(String),
updatedAt: expect.any(String),
};
+
+export const expectedTag: Partial<Tag> = {
+ id: expect.any(String),
+ createdAt: expect.any(String),
+ updatedAt: expect.any(String),
+};