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 tag creation and deletion tests

Kiran K49239d0813bf
diff --git a/apps/web/tests/tags/create-tag-error.test.ts b/apps/web/tests/tags/create-tag-error.test.ts
index 3ab241a6c8..f6ac6ccb72 100644
--- a/apps/web/tests/tags/create-tag-error.test.ts
+++ b/apps/web/tests/tags/create-tag-error.test.ts
@@ -1,6 +1,5 @@
import { Tag } from "@prisma/client";
import { expect, test } from "vitest";
-import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
const cases = [
@@ -45,16 +44,9 @@ const cases = [
cases.forEach(({ name, body, expected }) => {
test(name, async (ctx) => {
const h = new IntegrationHarness(ctx);
- const { workspace, apiKey } = await h.init();
+ const { workspace, http } = await h.init();
const { workspaceId } = workspace;
- const http = new HttpClient({
- baseUrl: h.baseUrl,
- headers: {
- Authorization: `Bearer ${apiKey.token}`,
- },
- });
-
const response = await http.post<Tag>({
path: "/tags",
query: { workspaceId },
@@ -67,16 +59,9 @@ cases.forEach(({ name, body, expected }) => {
test("create tag with existing name", async (ctx) => {
const h = new IntegrationHarness(ctx);
- const { workspace, apiKey } = await h.init();
+ const { workspace, http } = await h.init();
const { workspaceId } = workspace;
- const http = new HttpClient({
- baseUrl: h.baseUrl,
- headers: {
- Authorization: `Bearer ${apiKey.token}`,
- },
- });
-
await http.post({
path: "/tags",
query: { workspaceId },
diff --git a/apps/web/tests/tags/create-tag.test.ts b/apps/web/tests/tags/create-tag.test.ts
index e13fca0e59..5ea5bafc0d 100644
--- a/apps/web/tests/tags/create-tag.test.ts
+++ b/apps/web/tests/tags/create-tag.test.ts
@@ -1,28 +1,18 @@
import { Tag } from "@prisma/client";
-import { expect, inject, test } from "vitest";
-import { HttpClient } from "../utils/http";
+import { expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
import { expectedTag } from "../utils/schema";
test("POST /tags", async (ctx) => {
- console.log("inject", inject("workspace"));
-
const h = new IntegrationHarness(ctx);
- const { workspace, apiKey } = await h.init();
+ const { workspace, http } = await h.init();
const { workspaceId } = workspace;
- const http = new HttpClient({
- baseUrl: h.baseUrl,
- headers: {
- Authorization: `Bearer ${apiKey.token}`,
- },
- });
-
const { status, data: tag } = await http.post<Tag>({
path: "/tags",
query: { workspaceId },
body: {
- tag: "news",
+ tag: "social",
color: "red",
},
});
@@ -30,8 +20,10 @@ test("POST /tags", async (ctx) => {
expect(status).toEqual(201);
expect(tag).toEqual({
...expectedTag,
- name: "news",
+ name: "social",
color: "red",
projectId: workspace.id,
});
+
+ await h.deleteTag(tag.id);
});
diff --git a/apps/web/tests/tags/list-tags.test.ts b/apps/web/tests/tags/list-tags.test.ts
index 6e7cdea058..5e6d2f453a 100644
--- a/apps/web/tests/tags/list-tags.test.ts
+++ b/apps/web/tests/tags/list-tags.test.ts
@@ -1,18 +1,10 @@
import { Tag } from "@prisma/client";
import { expect, test } from "vitest";
-import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";
test("GET /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 { workspace, http } = await h.init();
const tagsToCreate = [
{ tag: "news", color: "red" },
@@ -46,4 +38,6 @@ test("GET /tags", async (ctx) => {
color: "green",
},
]);
+
+ await Promise.all(tags.map((tag) => h.deleteTag(tag.id)));
});
diff --git a/apps/web/tests/utils/integration.ts b/apps/web/tests/utils/integration.ts
index 8218e5c9ff..364d32a49f 100644
--- a/apps/web/tests/utils/integration.ts
+++ b/apps/web/tests/utils/integration.ts
@@ -86,4 +86,14 @@ export class IntegrationHarness {
query: { workspaceId },
});
}
+
+ // Delete tag
+ public async deleteTag(id: string) {
+ const { workspaceId } = this.resources.workspace;
+
+ await this.http.delete({
+ path: `/tags/${id}`,
+ query: { workspaceId },
+ });
+ }
}