diff --git a/lacommunaute/notification/tests/tests_utils.py b/lacommunaute/notification/tests/tests_utils.py index 7bcacfc1a..870fd898e 100644 --- a/lacommunaute/notification/tests/tests_utils.py +++ b/lacommunaute/notification/tests/tests_utils.py @@ -1,7 +1,7 @@ from django.test import TestCase from faker import Faker -from lacommunaute.forum_conversation.factories import TopicFactory +from lacommunaute.forum_conversation.factories import PostFactory, TopicFactory from lacommunaute.notification.factories import EmailSentTrackFactory, NotificationFactory from lacommunaute.notification.models import EmailSentTrack from lacommunaute.notification.utils import ( @@ -50,24 +50,27 @@ def test_order_by_date_joined(self): self.assertEqual(list(collect_new_users_for_onboarding()), list(User.objects.all().order_by("date_joined"))) -class GetSeriaizedMessagesTestCase(TestCase): - @classmethod - def setUpTestData(cls): - cls.topic = TopicFactory(with_post=True) - - def test_get_serialized_messages(self): - post = self.topic.first_post +class TestGetSerializedMessages: + def test_post_is_topic_head(self, db): + topic = TopicFactory(with_post=True) + notifications = [NotificationFactory(post=topic.first_post)] + assert get_serialized_messages(notifications) == [ + { + "poster": topic.first_post.poster_display_name, + "action": "a posé une nouvelle question", + "forum": topic.forum.name, + "url": topic.get_absolute_url(with_fqdn=True), + } + ] + + def test_post_is_not_topic_head(self, db): + post = PostFactory(topic=TopicFactory(with_post=True)) notifications = [NotificationFactory(post=post)] - - serialized_content = get_serialized_messages(notifications) - self.assertEqual( - serialized_content, - [ - { - "poster": post.poster_display_name, - "action": f"a répondu à '{post.subject}'", - "forum": self.topic.forum.name, - "url": self.topic.get_absolute_url(with_fqdn=True), - } - ], - ) + assert get_serialized_messages(notifications) == [ + { + "poster": post.poster_display_name, + "action": f"a répondu à '{post.subject}'", + "forum": post.topic.forum.name, + "url": post.topic.get_absolute_url(with_fqdn=True), + } + ] diff --git a/lacommunaute/notification/utils.py b/lacommunaute/notification/utils.py index 16f7e799e..8b29ed61b 100644 --- a/lacommunaute/notification/utils.py +++ b/lacommunaute/notification/utils.py @@ -21,7 +21,7 @@ def get_serialized_messages(notifications): return [ { "poster": n.post.poster_display_name, - "action": f"a répondu à '{n.post.subject}'", + "action": "a posé une nouvelle question" if n.post.is_topic_head else f"a répondu à '{n.post.subject}'", "forum": n.post.topic.forum.name, "url": n.post.topic.get_absolute_url(with_fqdn=True), }