aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-12-27 00:57:32 +0000
committerMohamed Bassem <me@mbassem.com>2025-12-27 00:57:32 +0000
commite82694debf3fce51e2825221f13395ab4509945b (patch)
tree9970ae420149cad3fdfefe6b849e0ce9ebe45831 /packages
parent2dbdf76c75852f14fee9564b7b29be070754ed5b (diff)
downloadkarakeep-e82694debf3fce51e2825221f13395ab4509945b.tar.zst
fix(tests): fix the asset upload tests
Diffstat (limited to 'packages')
-rw-r--r--packages/e2e_tests/fixtures/test.pdf38
-rw-r--r--packages/e2e_tests/tests/api/assets.test.ts17
-rw-r--r--packages/e2e_tests/tests/api/public.test.ts13
-rw-r--r--packages/e2e_tests/utils/assets.ts11
4 files changed, 58 insertions, 21 deletions
diff --git a/packages/e2e_tests/fixtures/test.pdf b/packages/e2e_tests/fixtures/test.pdf
new file mode 100644
index 00000000..008f870f
--- /dev/null
+++ b/packages/e2e_tests/fixtures/test.pdf
@@ -0,0 +1,38 @@
+%PDF-1.4
+1 0 obj
+<<
+/Type /Catalog
+/Pages 2 0 R
+>>
+endobj
+
+2 0 obj
+<<
+/Type /Pages
+/Kids [3 0 R]
+/Count 1
+>>
+endobj
+
+3 0 obj
+<<
+/Type /Page
+/Parent 2 0 R
+/MediaBox [0 0 612 792]
+>>
+endobj
+
+xref
+0 4
+0000000000 65535 f
+0000000010 00000 n
+0000000053 00000 n
+0000000125 00000 n
+trailer
+<<
+/Size 4
+/Root 1 0 R
+>>
+startxref
+173
+%%EOF
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/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;
diff --git a/packages/e2e_tests/utils/assets.ts b/packages/e2e_tests/utils/assets.ts
new file mode 100644
index 00000000..efcfec81
--- /dev/null
+++ b/packages/e2e_tests/utils/assets.ts
@@ -0,0 +1,11 @@
+import * as fs from "fs";
+import * as path from "path";
+
+const pdfFixturePath = path.join(__dirname, "..", "fixtures", "test.pdf");
+const pdfContent = fs.readFileSync(pdfFixturePath);
+
+export function createTestPdfFile(fileName = "test.pdf"): File {
+ return new File([pdfContent], fileName, {
+ type: "application/pdf",
+ });
+}