aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers/bookmarks.test.ts
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2025-04-07 01:03:26 +0100
committerMohamedBassem <me@mbassem.com>2025-04-08 03:48:12 -0700
commit3207264fc13c275d6dcfbd2628cc6b3974ceeaed (patch)
treed426ffe0fe6bc3b9e692d96af94aa8d5d2a51162 /packages/trpc/routers/bookmarks.test.ts
parent817eb58832a3e715e21892417b7624f4b1cf0d46 (diff)
downloadkarakeep-3207264fc13c275d6dcfbd2628cc6b3974ceeaed.tar.zst
feat: Allow editing bookmark details
Diffstat (limited to 'packages/trpc/routers/bookmarks.test.ts')
-rw-r--r--packages/trpc/routers/bookmarks.test.ts63
1 files changed, 62 insertions, 1 deletions
diff --git a/packages/trpc/routers/bookmarks.test.ts b/packages/trpc/routers/bookmarks.test.ts
index d89f80fd..c3469acc 100644
--- a/packages/trpc/routers/bookmarks.test.ts
+++ b/packages/trpc/routers/bookmarks.test.ts
@@ -60,9 +60,70 @@ describe("Bookmark Routes", () => {
favourited: true,
});
- const res = await api.getBookmark({ bookmarkId: bookmark.id });
+ let res = await api.getBookmark({ bookmarkId: bookmark.id });
expect(res.archived).toBeTruthy();
expect(res.favourited).toBeTruthy();
+
+ // Update other common fields
+ const newDate = new Date(Date.now() - 1000 * 60 * 60 * 24); // Yesterday
+ newDate.setMilliseconds(0);
+ await api.updateBookmark({
+ bookmarkId: bookmark.id,
+ title: "New Title",
+ note: "Test Note",
+ summary: "Test Summary",
+ createdAt: newDate,
+ });
+
+ res = await api.getBookmark({ bookmarkId: bookmark.id });
+ expect(res.title).toEqual("New Title");
+ expect(res.note).toEqual("Test Note");
+ expect(res.summary).toEqual("Test Summary");
+ expect(res.createdAt).toEqual(newDate);
+
+ // Update link-specific fields
+ const linkUpdateDate = new Date(Date.now() - 1000 * 60 * 60 * 48); // 2 days ago
+ linkUpdateDate.setMilliseconds(0);
+ await api.updateBookmark({
+ bookmarkId: bookmark.id,
+ url: "https://new-google.com",
+ description: "New Description",
+ author: "New Author",
+ publisher: "New Publisher",
+ datePublished: linkUpdateDate,
+ dateModified: linkUpdateDate,
+ });
+
+ res = await api.getBookmark({ bookmarkId: bookmark.id });
+ assert(res.content.type === BookmarkTypes.LINK);
+ expect(res.content.url).toEqual("https://new-google.com");
+ expect(res.content.description).toEqual("New Description");
+ expect(res.content.author).toEqual("New Author");
+ expect(res.content.publisher).toEqual("New Publisher");
+ expect(res.content.datePublished).toEqual(linkUpdateDate);
+ expect(res.content.dateModified).toEqual(linkUpdateDate);
+ });
+
+ test<CustomTestContext>("update bookmark - non-link type error", async ({
+ apiCallers,
+ }) => {
+ const api = apiCallers[0].bookmarks;
+
+ // Create a TEXT bookmark
+ const bookmark = await api.createBookmark({
+ text: "Initial text",
+ type: BookmarkTypes.TEXT,
+ });
+
+ // Attempt to update link-specific fields
+ await expect(() =>
+ api.updateBookmark({
+ bookmarkId: bookmark.id,
+ url: "https://should-fail.com", // Link-specific field
+ }),
+ ).rejects.toThrow(
+ /Attempting to set link attributes for non-link type bookmark/,
+ );
});
test<CustomTestContext>("list bookmarks", async ({ apiCallers }) => {