From 3207264fc13c275d6dcfbd2628cc6b3974ceeaed Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 7 Apr 2025 01:03:26 +0100 Subject: feat: Allow editing bookmark details --- packages/trpc/routers/bookmarks.test.ts | 63 ++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'packages/trpc/routers/bookmarks.test.ts') 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("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("list bookmarks", async ({ apiCallers }) => { -- cgit v1.2.3-70-g09d2