Skip to content

Commit 1839e7f

Browse files
ilaswCopilotAmarTrebinjac
authored
feat: add support for multiple squad posting and notification dedup (#3154)
Co-authored-by: Copilot <[email protected]> Co-authored-by: Amar Trebinjac <[email protected]>
1 parent ff5a738 commit 1839e7f

File tree

13 files changed

+1307
-96
lines changed

13 files changed

+1307
-96
lines changed

__tests__/notifications/index.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,51 @@ describe('storeNotificationBundle', () => {
16691669
expect(notifications.length).toEqual(3);
16701670
});
16711671

1672+
it('should not generate duplicate post added notifications for posts with same dedupKey', async () => {
1673+
await saveFixtures(con, User, usersFixture);
1674+
1675+
const dedupKey = 'p1';
1676+
const sharedCtx = {
1677+
userIds: [userId, '3', '4'],
1678+
source: sourcesFixture[0] as Reference<Source>,
1679+
user: usersFixture[1] as Reference<User>,
1680+
doneBy: usersFixture[1] as Reference<User>,
1681+
};
1682+
const ctx1 = {
1683+
...sharedCtx,
1684+
post: postsFixture[1] as Reference<Post>,
1685+
};
1686+
const ctx2 = {
1687+
...sharedCtx,
1688+
post: postsFixture[2] as Reference<Post>,
1689+
};
1690+
1691+
const notificationIds = await con.transaction(async (manager) => {
1692+
const results = await Promise.all([
1693+
storeNotificationBundleV2(
1694+
manager,
1695+
generateNotificationV2(NotificationType.SourcePostAdded, ctx1),
1696+
dedupKey,
1697+
),
1698+
storeNotificationBundleV2(
1699+
manager,
1700+
generateNotificationV2(NotificationType.SquadPostAdded, ctx2),
1701+
dedupKey,
1702+
),
1703+
]);
1704+
return results.flat();
1705+
});
1706+
1707+
const notifications = await con.getRepository(UserNotification).findBy({
1708+
notificationId: In(notificationIds.map((item) => item.id)),
1709+
});
1710+
1711+
expect(notifications.length).toEqual(3);
1712+
const uniqueKeys = notifications.map((item) => item.uniqueKey);
1713+
expect(new Set(uniqueKeys).size).toEqual(1);
1714+
expect(uniqueKeys[0]).toEqual(`post_added:dedup_${dedupKey}:post`);
1715+
});
1716+
16721717
it('should generate user_given_top_reader notification', async () => {
16731718
const topReader = {
16741719
id: 'cdaac113-0e8b-4189-9a6b-ceea7b21de0e',

0 commit comments

Comments
 (0)