Skip to content

Commit

Permalink
tests: Add tests for bookmark deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed May 12, 2024
1 parent d33be14 commit ecfcba5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/trpc/routers/bookmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit ecfcba5

Please sign in to comment.