diff options
| author | MohamedBassem <me@mbassem.com> | 2024-05-06 19:03:41 +0100 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-05-12 14:00:00 +0100 |
| commit | ecfcba5aaa3cba474eef9ddae6c02735c93391bc (patch) | |
| tree | 5f750d34aa0ea5036b510ba5a7af0e0f0a4e5cb8 | |
| parent | d33be149e661945fe67a9b6c4ff0d1e47917b8cd (diff) | |
| download | karakeep-ecfcba5aaa3cba474eef9ddae6c02735c93391bc.tar.zst | |
tests: Add tests for bookmark deduplication
| -rw-r--r-- | packages/trpc/routers/bookmarks.test.ts | 38 |
1 files changed, 38 insertions, 0 deletions
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<CustomTestContext>("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); + }); }); |
