Skip to content

Commit

Permalink
feat: group only unseen notifications for all types
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadadeeltajamul committed Dec 20, 2024
1 parent 42dc3e6 commit 4169b16
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,12 @@ def get_user_existing_notifications(user_ids, notification_type, group_by_id, co
"""
Returns user last group able notification
"""
notification_type_params = {
'new_discussion_post': {'last_seen__isnull': True},
}
notifications = Notification.objects.filter(
user__in=user_ids,
notification_type=notification_type,
group_by_id=group_by_id,
course_id=course_id,
**notification_type_params.get(notification_type, {})
last_seen__isnull=True,
)
notifications_mapping = {user_id: [] for user_id in user_ids}
for notification in notifications:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def test_group_email_content(self):
self.assertEqual(content_context['email_content'], 'new content')


@ddt.ddt
class TestNewPostGrouper(ModuleStoreTestCase):
class TestNewPostGrouper(unittest.TestCase):
"""
Tests for the NewPostGrouper class
"""
Expand Down Expand Up @@ -147,38 +146,9 @@ def test_new_post_with_same_user(self):

self.assertFalse(updated_context.get('grouped', False))

@ddt.data(datetime(2023, 1, 1, tzinfo=utc), None)
def test_not_grouped_when_notification_is_seen(self, last_seen):
"""
Notification is not grouped if the notification is marked as seen
"""
course = CourseFactory()
user = UserFactory()
notification_params = {
'app_name': 'discussion',
'notification_type': 'new_discussion_post',
'course_id': course.id,
'group_by_id': course.id,
'content_url': 'http://example.com',
'user': user,
'last_seen': last_seen,
}
Notification.objects.create(content_context={
'username': 'User1',
'post_title': ' Post title',
'replier_name': 'User 1',

}, **notification_params)
existing_notifications = get_user_existing_notifications(
[user.id], 'new_discussion_post', course.id, course.id
)
if last_seen is None:
assert existing_notifications[user.id] is not None
else:
assert existing_notifications[user.id] is None


class TestGroupUserNotifications(unittest.TestCase):
@ddt.ddt
class TestGroupUserNotifications(ModuleStoreTestCase):
"""
Tests for the group_user_notifications function
"""
Expand Down Expand Up @@ -214,6 +184,36 @@ def test_group_user_notifications_no_grouper(self):

self.assertFalse(old_notification.save.called)

@ddt.data(datetime(2023, 1, 1, tzinfo=utc), None)
def test_not_grouped_when_notification_is_seen(self, last_seen):
"""
Notification is not grouped if the notification is marked as seen
"""
course = CourseFactory()
user = UserFactory()
notification_params = {
'app_name': 'discussion',
'notification_type': 'new_discussion_post',
'course_id': course.id,
'group_by_id': course.id,
'content_url': 'http://example.com',
'user': user,
'last_seen': last_seen,
}
Notification.objects.create(content_context={
'username': 'User1',
'post_title': ' Post title',
'replier_name': 'User 1',

}, **notification_params)
existing_notifications = get_user_existing_notifications(
[user.id], 'new_discussion_post', course.id, course.id
)
if last_seen is None:
assert existing_notifications[user.id] is not None
else:
assert existing_notifications[user.id] is None


class TestGetUserExistingNotifications(unittest.TestCase):
"""
Expand Down

0 comments on commit 4169b16

Please sign in to comment.