-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): passer les notifications en lues qd un utilisateu…
…r répond
- Loading branch information
1 parent
62d9593
commit e2f3400
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
from django.contrib.auth.models import AnonymousUser | ||
from django.db.models import F | ||
from django.test import TestCase | ||
|
||
from lacommunaute.forum_conversation.factories import TopicFactory | ||
from lacommunaute.notification.enums import EmailSentTrackKind | ||
from lacommunaute.notification.factories import NotificationFactory | ||
from lacommunaute.notification.models import EmailSentTrack, Notification | ||
from lacommunaute.users.factories import UserFactory | ||
|
||
|
||
class EmailSentTrackModelTest(TestCase): | ||
|
@@ -31,3 +35,57 @@ def test_notification_group_by_recipient(self): | |
) | ||
|
||
self.assertEqual(result[recipient_b], [notification_b]) | ||
|
||
def test_mark_topic_posts_read(self): | ||
user = UserFactory() | ||
topic = TopicFactory(with_post=True) | ||
|
||
NotificationFactory.create_batch(2, recipient=user.email, post=topic.first_post) | ||
|
||
Notification.objects.mark_topic_posts_read(topic, user) | ||
|
||
self.assertEqual( | ||
Notification.objects.filter( | ||
sent_at__isnull=False, post=topic.first_post, recipient=user.email, sent_at=F("created") | ||
).count(), | ||
2, | ||
) | ||
|
||
def test_mark_topic_posts_read_doesnt_impact_old_notifications(self): | ||
user = UserFactory() | ||
topic = TopicFactory(with_post=True) | ||
|
||
old_notification = NotificationFactory(recipient=user.email, post=topic.first_post, is_sent=True) | ||
self.assertNotEqual(str(old_notification.sent_at), str(old_notification.created)) | ||
|
||
Notification.objects.mark_topic_posts_read(topic, user) | ||
|
||
old_notification.refresh_from_db() | ||
self.assertNotEqual(str(old_notification.sent_at), str(old_notification.created)) | ||
|
||
def test_mark_topic_posts_read_doesnt_impact_other_notifications(self): | ||
user = UserFactory() | ||
topic = TopicFactory(with_post=True) | ||
|
||
other_notification = NotificationFactory(recipient="[email protected]", post=topic.first_post) | ||
|
||
Notification.objects.mark_topic_posts_read(topic, user) | ||
|
||
other_notification.refresh_from_db() | ||
self.assertIsNone(other_notification.sent_at) | ||
|
||
def test_mark_topic_posts_read_anonymous_user(self): | ||
topic = TopicFactory(with_post=True) | ||
|
||
with self.assertRaises(ValueError): | ||
Notification.objects.mark_topic_posts_read(topic, AnonymousUser()) | ||
|
||
def test_mark_topic_posts_read_invalid_arguments(self): | ||
user = UserFactory() | ||
topic = TopicFactory(with_post=True) | ||
|
||
with self.assertRaises(ValueError): | ||
Notification.objects.mark_topic_posts_read(None, user) | ||
|
||
with self.assertRaises(ValueError): | ||
Notification.objects.mark_topic_posts_read(topic, None) |