Skip to content

Commit

Permalink
fix(notification): mis à jour le champ sent_at
Browse files Browse the repository at this point in the history
  • Loading branch information
calummackervoy committed Jul 3, 2024
1 parent bfc2d8b commit ababa8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lacommunaute/notification/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf import settings
from django.template.defaultfilters import pluralize
from django.urls import reverse
from django.utils import timezone

from config.settings.base import DEFAULT_FROM_EMAIL, NEW_MESSAGES_EMAIL_MAX_PREVIEW, SIB_NEW_MESSAGES_TEMPLATE
from lacommunaute.forum.models import Forum
Expand All @@ -14,12 +15,12 @@
def send_messages_notifications(delay: NotificationDelay):
"""Notifications are scheduled in the application and then processed later by this task"""

notifications = Notification.objects.filter(delay=delay, sent_at__isnull=True, post__isnull=False).select_related(
"post", "post__topic", "post__poster"
)

def get_grouped_notifications():
return (
Notification.objects.filter(delay=delay, sent_at__isnull=True, post__isnull=False)
.select_related("post", "post__topic", "post__poster")
.group_by_recipient()
)
return notifications.group_by_recipient()

grouped_notifications = get_grouped_notifications()
for recipient in grouped_notifications.keys():
Expand All @@ -40,6 +41,8 @@ def get_grouped_notifications():
template_id=SIB_NEW_MESSAGES_TEMPLATE,
)

notifications.bulk_update(sent_at=timezone.now())


def add_user_to_list_when_register():
new_users = collect_new_users_for_onboarding()
Expand Down
6 changes: 6 additions & 0 deletions lacommunaute/notification/tests/tests_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def test_send_messages_notifications_asap(self):
email_sent_track.datas, self.get_expected_email_payload(Notification.objects.filter(id=notification.id))
)

self.assertIsNone(Notification.objects.filter(sent_at__isnull=True).first())
self.assertEqual(Notification.objects.all().values("sent_at").distinct(), 1)

@respx.mock
def test_send_messages_notifications_day(self):
topic = TopicFactory(with_post=True)
Expand All @@ -97,6 +100,9 @@ def test_send_messages_notifications_day(self):
email_sent_track.datas, self.get_expected_email_payload(Notification.objects.filter(id=notification.id))
)

self.assertIsNone(Notification.objects.filter(sent_at__isnull=True).first())
self.assertEqual(Notification.objects.all().values("sent_at").distinct(), 1)

@respx.mock
def test_send_messages_notifications_max_messages_preview(self):
topic = TopicFactory(with_post=True)
Expand Down

0 comments on commit ababa8c

Please sign in to comment.