aboutsummaryrefslogtreecommitdiffstats
path: root/packages/e2e_tests/tests/api/bookmarks.test.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-01-05 12:01:42 +0000
committerMohamed Bassem <me@mbassem.com>2025-01-05 12:01:42 +0000
commit1f5d5668b7558ec4d0a77129041cba3ba6d72cb7 (patch)
tree547276fbc89d5337c2f32ff6bcb37abe05f5c5dc /packages/e2e_tests/tests/api/bookmarks.test.ts
parentce16eda75f4d93646e485b7115398e81e7c88acc (diff)
downloadkarakeep-1f5d5668b7558ec4d0a77129041cba3ba6d72cb7.tar.zst
feat: Expose the search functionality in the REST API
Diffstat (limited to 'packages/e2e_tests/tests/api/bookmarks.test.ts')
-rw-r--r--packages/e2e_tests/tests/api/bookmarks.test.ts109
1 files changed, 109 insertions, 0 deletions
diff --git a/packages/e2e_tests/tests/api/bookmarks.test.ts b/packages/e2e_tests/tests/api/bookmarks.test.ts
index 727ca758..7c605aab 100644
--- a/packages/e2e_tests/tests/api/bookmarks.test.ts
+++ b/packages/e2e_tests/tests/api/bookmarks.test.ts
@@ -285,4 +285,113 @@ describe("Bookmarks API", () => {
expect(removeTagsRes.status).toBe(200);
});
+
+ it("should search bookmarks", async () => {
+ // Create test bookmarks
+ await client.POST("/bookmarks", {
+ body: {
+ type: "text",
+ title: "Search Test 1",
+ text: "This is a test bookmark for search",
+ },
+ });
+ await client.POST("/bookmarks", {
+ body: {
+ type: "text",
+ title: "Search Test 2",
+ text: "Another test bookmark for search",
+ },
+ });
+
+ // Wait 3 seconds for the search index to be updated
+ // TODO: Replace with a check that all queues are empty
+ await new Promise((f) => setTimeout(f, 3000));
+
+ // Search for bookmarks
+ const { data: searchResults, response: searchResponse } = await client.GET(
+ "/bookmarks/search",
+ {
+ params: {
+ query: {
+ q: "test bookmark",
+ },
+ },
+ },
+ );
+
+ expect(searchResponse.status).toBe(200);
+ expect(searchResults!.bookmarks.length).toBeGreaterThanOrEqual(2);
+ });
+
+ it("should paginate search results", async () => {
+ // Create multiple bookmarks
+ const bookmarkPromises = Array.from({ length: 5 }, (_, i) =>
+ client.POST("/bookmarks", {
+ body: {
+ type: "text",
+ title: `Search Pagination ${i}`,
+ text: `This is test bookmark ${i} for pagination`,
+ },
+ }),
+ );
+
+ await Promise.all(bookmarkPromises);
+
+ // Wait 3 seconds for the search index to be updated
+ // TODO: Replace with a check that all queues are empty
+ await new Promise((f) => setTimeout(f, 3000));
+
+ // Get first page
+ const { data: firstPage, response: firstResponse } = await client.GET(
+ "/bookmarks/search",
+ {
+ params: {
+ query: {
+ q: "pagination",
+ limit: 2,
+ },
+ },
+ },
+ );
+
+ expect(firstResponse.status).toBe(200);
+ expect(firstPage!.bookmarks.length).toBe(2);
+ expect(firstPage!.nextCursor).toBeDefined();
+
+ // Get second page
+ const { data: secondPage, response: secondResponse } = await client.GET(
+ "/bookmarks/search",
+ {
+ params: {
+ query: {
+ q: "pagination",
+ limit: 2,
+ cursor: firstPage!.nextCursor!,
+ },
+ },
+ },
+ );
+
+ expect(secondResponse.status).toBe(200);
+ expect(secondPage!.bookmarks.length).toBe(2);
+ expect(secondPage!.nextCursor).toBeDefined();
+
+ // Get final page
+ const { data: finalPage, response: finalResponse } = await client.GET(
+ "/bookmarks/search",
+ {
+ params: {
+ query: {
+ q: "pagination",
+ limit: 2,
+ cursor: secondPage!.nextCursor!,
+ },
+ },
+ },
+ );
+
+ expect(finalResponse.status).toBe(200);
+ expect(finalPage!.bookmarks.length).toBe(1);
+ expect(finalPage!.nextCursor).toBeNull();
+ });
});