From ecfcba5aaa3cba474eef9ddae6c02735c93391bc Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 6 May 2024 19:03:41 +0100 Subject: tests: Add tests for bookmark deduplication --- packages/trpc/routers/bookmarks.test.ts | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/trpc/routers/bookmarks.test.ts b/packages/trpc/routers/bookmarks.test.ts index 1bcd3279..d739da0c 100644 --- a/packages/trpc/routers/bookmarks.test.ts +++ b/packages/trpc/routers/bookmarks.test.ts @@ -212,4 +212,42 @@ describe("Bookmark Routes", () => { ), ).toEqual([user2Bookmark.id]); }); + + test("bookmark links dedup", async ({ apiCallers }) => { + // Two users with google in their bookmarks + const bookmark1User1 = await apiCallers[0].bookmarks.createBookmark({ + url: "https://google.com", + type: "link", + }); + expect(bookmark1User1.alreadyExists).toEqual(false); + + const bookmark1User2 = await apiCallers[1].bookmarks.createBookmark({ + url: "https://google.com", + type: "link", + }); + expect(bookmark1User2.alreadyExists).toEqual(false); + + // User1 attempting to re-add google. Should return the existing bookmark + const bookmark2User1 = await apiCallers[0].bookmarks.createBookmark({ + url: "https://google.com", + type: "link", + }); + expect(bookmark2User1.alreadyExists).toEqual(true); + expect(bookmark2User1.id).toEqual(bookmark1User1.id); + + // User2 attempting to re-add google. Should return the existing bookmark + const bookmark2User2 = await apiCallers[1].bookmarks.createBookmark({ + url: "https://google.com", + type: "link", + }); + expect(bookmark2User2.alreadyExists).toEqual(true); + expect(bookmark2User2.id).toEqual(bookmark1User2.id); + + // User1 adding google2. Should not return an existing bookmark + const bookmark3User1 = await apiCallers[0].bookmarks.createBookmark({ + url: "https://google2.com", + type: "link", + }); + expect(bookmark3User1.alreadyExists).toEqual(false); + }); }); -- cgit v1.2.3-70-g09d2