diff options
Diffstat (limited to '')
| -rw-r--r-- | packages/e2e_tests/tests/api/assets.test.ts | 17 | ||||
| -rw-r--r-- | packages/e2e_tests/tests/api/bookmarks.test.ts | 70 | ||||
| -rw-r--r-- | packages/e2e_tests/tests/api/public.test.ts | 13 |
3 files changed, 79 insertions, 21 deletions
diff --git a/packages/e2e_tests/tests/api/assets.test.ts b/packages/e2e_tests/tests/api/assets.test.ts index accc5cf0..62b9a1e2 100644 --- a/packages/e2e_tests/tests/api/assets.test.ts +++ b/packages/e2e_tests/tests/api/assets.test.ts @@ -3,6 +3,7 @@ import { assert, beforeEach, describe, expect, inject, it } from "vitest"; import { createKarakeepClient } from "@karakeep/sdk"; import { createTestUser, uploadTestAsset } from "../../utils/api"; +import { createTestPdfFile } from "../../utils/assets"; describe("Assets API", () => { const port = inject("karakeepPort"); @@ -27,9 +28,7 @@ describe("Assets API", () => { it("should upload and retrieve an asset", async () => { // Create a test file - const file = new File(["test content"], "test.pdf", { - type: "application/pdf", - }); + const file = createTestPdfFile(); // Upload the asset const uploadResponse = await uploadTestAsset(apiKey, port, file); @@ -52,9 +51,7 @@ describe("Assets API", () => { it("should attach an asset to a bookmark", async () => { // Create a test file - const file = new File(["test content"], "test.pdf", { - type: "application/pdf", - }); + const file = createTestPdfFile(); // Upload the asset const uploadResponse = await uploadTestAsset(apiKey, port, file); @@ -91,9 +88,7 @@ describe("Assets API", () => { it("should delete asset when deleting bookmark", async () => { // Create a test file - const file = new File(["test content"], "test.pdf", { - type: "application/pdf", - }); + const file = createTestPdfFile(); // Upload the asset const uploadResponse = await uploadTestAsset(apiKey, port, file); @@ -154,9 +149,7 @@ describe("Assets API", () => { throw new Error("Bookmark creation failed"); } - const file = new File(["test content"], "test.pdf", { - type: "application/pdf", - }); + const file = createTestPdfFile(); // Upload the asset const uploadResponse1 = await uploadTestAsset(apiKey, port, file); diff --git a/packages/e2e_tests/tests/api/bookmarks.test.ts b/packages/e2e_tests/tests/api/bookmarks.test.ts index a6bc85e3..7c14ee61 100644 --- a/packages/e2e_tests/tests/api/bookmarks.test.ts +++ b/packages/e2e_tests/tests/api/bookmarks.test.ts @@ -289,6 +289,76 @@ describe("Bookmarks API", () => { expect(removeTagsRes.status).toBe(200); }); + it("should manage tags with attachedBy field", async () => { + // Create a new bookmark + const { data: createdBookmark, error: createError } = await client.POST( + "/bookmarks", + { + body: { + type: "text", + title: "Test Bookmark for attachedBy", + text: "Testing attachedBy field", + }, + }, + ); + + if (createError) { + console.error("Error creating bookmark:", createError); + throw createError; + } + if (!createdBookmark) { + throw new Error("Bookmark creation failed"); + } + + // Add tags with different attachedBy values + const { data: addTagsResponse, response: addTagsRes } = await client.POST( + "/bookmarks/{bookmarkId}/tags", + { + params: { + path: { + bookmarkId: createdBookmark.id, + }, + }, + body: { + tags: [ + { tagName: "ai-tag", attachedBy: "ai" }, + { tagName: "human-tag", attachedBy: "human" }, + { tagName: "default-tag" }, // Should default to "human" + ], + }, + }, + ); + + expect(addTagsRes.status).toBe(200); + expect(addTagsResponse!.attached.length).toBe(3); + + // Get the bookmark and verify the attachedBy values + const { data: retrievedBookmark } = await client.GET( + "/bookmarks/{bookmarkId}", + { + params: { + path: { + bookmarkId: createdBookmark.id, + }, + }, + }, + ); + + expect(retrievedBookmark!.tags.length).toBe(3); + + const aiTag = retrievedBookmark!.tags.find((t) => t.name === "ai-tag"); + const humanTag = retrievedBookmark!.tags.find( + (t) => t.name === "human-tag", + ); + const defaultTag = retrievedBookmark!.tags.find( + (t) => t.name === "default-tag", + ); + + expect(aiTag?.attachedBy).toBe("ai"); + expect(humanTag?.attachedBy).toBe("human"); + expect(defaultTag?.attachedBy).toBe("human"); + }); + it("should get lists for a bookmark", async () => { const { data: createdBookmark } = await client.POST("/bookmarks", { body: { diff --git a/packages/e2e_tests/tests/api/public.test.ts b/packages/e2e_tests/tests/api/public.test.ts index 59f50495..5025d078 100644 --- a/packages/e2e_tests/tests/api/public.test.ts +++ b/packages/e2e_tests/tests/api/public.test.ts @@ -6,6 +6,7 @@ import { zAssetSignedTokenSchema } from "@karakeep/shared/types/assets"; import { BookmarkTypes } from "@karakeep/shared/types/bookmarks"; import { createTestUser, uploadTestAsset } from "../../utils/api"; +import { createTestPdfFile } from "../../utils/assets"; import { waitUntil } from "../../utils/general"; import { getTrpcClient } from "../../utils/trpc"; @@ -43,9 +44,7 @@ describe("Public API", () => { }); // Create a second bookmark with an asset - const file = new File(["test content"], "test.pdf", { - type: "application/pdf", - }); + const file = createTestPdfFile(); const uploadResponse = await uploadTestAsset(currentApiKey, port, file); const createBookmark2 = await trpcClient.bookmarks.createBookmark.mutate({ @@ -160,9 +159,7 @@ describe("Public API", () => { const assetUpload = await uploadTestAsset( apiKey, port, - new File(["test content for token validation"], "token_test.pdf", { - type: "application/pdf", - }), + createTestPdfFile("token_test.pdf"), ); assetId = assetUpload.assetId; }); @@ -246,9 +243,7 @@ describe("Public API", () => { const anotherAssetUpload = await uploadTestAsset( apiKey, // Same user port, - new File(["other content"], "other_asset.pdf", { - type: "application/pdf", - }), + createTestPdfFile("other_asset.pdf"), ); const anotherAssetId = anotherAssetUpload.assetId; |
