Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notification): informer les abonnés dun forum des nouvelles questions #834

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions lacommunaute/notification/tests/tests_utils.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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),
}
]
2 changes: 1 addition & 1 deletion lacommunaute/notification/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down