aboutsummaryrefslogtreecommitdiffstats
path: root/packages/e2e_tests/tests/api/lists.test.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-12-30 16:55:49 +0000
committerMohamed Bassem <me@mbassem.com>2024-12-30 16:56:23 +0000
commit058e7238840b362135fd080045478025e31bf720 (patch)
treef094b35163961065d3d145e8ff826219b0bb3506 /packages/e2e_tests/tests/api/lists.test.ts
parent5aee3404aa7f446a221a88c9b2cd529d1249e22f (diff)
downloadkarakeep-058e7238840b362135fd080045478025e31bf720.tar.zst
chore: Setup and add e2e tests for the API endpoints
Diffstat (limited to 'packages/e2e_tests/tests/api/lists.test.ts')
-rw-r--r--packages/e2e_tests/tests/api/lists.test.ts185
1 files changed, 185 insertions, 0 deletions
diff --git a/packages/e2e_tests/tests/api/lists.test.ts b/packages/e2e_tests/tests/api/lists.test.ts
new file mode 100644
index 00000000..2a954b6f
--- /dev/null
+++ b/packages/e2e_tests/tests/api/lists.test.ts
@@ -0,0 +1,185 @@
+import { createHoarderClient } from "@hoarderapp/sdk";
+import { beforeEach, describe, expect, inject, it } from "vitest";
+
+import { createTestUser } from "../../utils/api";
+
+describe("Lists API", () => {
+ const port = inject("hoarderPort");
+
+ if (!port) {
+ throw new Error("Missing required environment variables");
+ }
+
+ let client: ReturnType<typeof createHoarderClient>;
+ let apiKey: string;
+
+ beforeEach(async () => {
+ apiKey = await createTestUser();
+ client = createHoarderClient({
+ baseUrl: `http://localhost:${port}/api/v1/`,
+ headers: {
+ "Content-Type": "application/json",
+ authorization: `Bearer ${apiKey}`,
+ },
+ });
+ });
+
+ it("should create, get, update and delete a list", async () => {
+ // Create a new list
+ const { data: createdList, response: createResponse } = await client.POST(
+ "/lists",
+ {
+ body: {
+ name: "Test List",
+ icon: "🚀",
+ },
+ },
+ );
+
+ expect(createResponse.status).toBe(201);
+ expect(createdList).toBeDefined();
+ expect(createdList?.id).toBeDefined();
+ expect(createdList?.name).toBe("Test List");
+
+ // Get the created list
+ const { data: retrievedList, response: getResponse } = await client.GET(
+ "/lists/{listId}",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ },
+ },
+ },
+ );
+
+ expect(getResponse.status).toBe(200);
+ expect(retrievedList!.id).toBe(createdList!.id);
+ expect(retrievedList!.name).toBe("Test List");
+
+ // Update the list
+ const { data: updatedList, response: updateResponse } = await client.PATCH(
+ "/lists/{listId}",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ },
+ },
+ body: {
+ name: "Updated List",
+ },
+ },
+ );
+
+ expect(updateResponse.status).toBe(200);
+ expect(updatedList!.name).toBe("Updated List");
+
+ // Delete the list
+ const { response: deleteResponse } = await client.DELETE(
+ "/lists/{listId}",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ },
+ },
+ },
+ );
+
+ expect(deleteResponse.status).toBe(204);
+
+ // Verify it's deleted
+ const { response: getDeletedResponse } = await client.GET(
+ "/lists/{listId}",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ },
+ },
+ },
+ );
+
+ expect(getDeletedResponse.status).toBe(404);
+ });
+
+ it("should manage bookmarks in a list", async () => {
+ // Create a list
+ const { data: createdList } = await client.POST("/lists", {
+ body: {
+ name: "Test List",
+ icon: "🚀",
+ },
+ });
+
+ // Create a bookmark
+ const { data: createdBookmark } = await client.POST("/bookmarks", {
+ body: {
+ type: "text",
+ title: "Test Bookmark",
+ text: "This is a test bookmark",
+ },
+ });
+
+ // Add bookmark to list
+ const { response: addResponse } = await client.PUT(
+ "/lists/{listId}/bookmarks/{bookmarkId}",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ bookmarkId: createdBookmark!.id,
+ },
+ },
+ },
+ );
+
+ expect(addResponse.status).toBe(204);
+
+ // Get bookmarks in list
+ const { data: listBookmarks, response: getResponse } = await client.GET(
+ "/lists/{listId}/bookmarks",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ },
+ },
+ },
+ );
+
+ expect(getResponse.status).toBe(200);
+ expect(listBookmarks!.bookmarks.length).toBe(1);
+ expect(listBookmarks!.bookmarks[0].id).toBe(createdBookmark!.id);
+
+ // Remove bookmark from list
+ const { response: removeResponse } = await client.DELETE(
+ "/lists/{listId}/bookmarks/{bookmarkId}",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ bookmarkId: createdBookmark!.id,
+ },
+ },
+ },
+ );
+
+ expect(removeResponse.status).toBe(204);
+
+ // Verify bookmark is removed
+ const { data: updatedListBookmarks } = await client.GET(
+ "/lists/{listId}/bookmarks",
+ {
+ params: {
+ path: {
+ listId: createdList!.id,
+ },
+ },
+ },
+ );
+
+ expect(updatedListBookmarks!.bookmarks.length).toBe(0);
+ });
+});