1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.NotificationTest do
11 alias Pleroma.Notification
12 alias Pleroma.Tests.ObanHelpers
14 alias Pleroma.Web.ActivityPub.Transmogrifier
15 alias Pleroma.Web.CommonAPI
16 alias Pleroma.Web.Push
17 alias Pleroma.Web.Streamer
19 describe "create_notifications" do
20 test "creates a notification for an emoji reaction" do
22 other_user = insert(:user)
24 {:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"})
25 {:ok, activity, _object} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
27 {:ok, [notification]} = Notification.create_notifications(activity)
29 assert notification.user_id == user.id
32 test "notifies someone when they are directly addressed" do
34 other_user = insert(:user)
35 third_user = insert(:user)
38 CommonAPI.post(user, %{
39 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
42 {:ok, [notification, other_notification]} = Notification.create_notifications(activity)
44 notified_ids = Enum.sort([notification.user_id, other_notification.user_id])
45 assert notified_ids == [other_user.id, third_user.id]
46 assert notification.activity_id == activity.id
47 assert other_notification.activity_id == activity.id
50 test "it creates a notification for subscribed users" do
52 subscriber = insert(:user)
54 User.subscribe(subscriber, user)
56 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
57 {:ok, [notification]} = Notification.create_notifications(status)
59 assert notification.user_id == subscriber.id
62 test "does not create a notification for subscribed users if status is a reply" do
64 other_user = insert(:user)
65 subscriber = insert(:user)
67 User.subscribe(subscriber, other_user)
69 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
71 {:ok, _reply_activity} =
72 CommonAPI.post(other_user, %{
73 "status" => "test reply",
74 "in_reply_to_status_id" => activity.id
77 user_notifications = Notification.for_user(user)
78 assert length(user_notifications) == 1
80 subscriber_notifications = Notification.for_user(subscriber)
81 assert Enum.empty?(subscriber_notifications)
85 describe "CommonApi.post/2 notification-related functionality" do
86 test_with_mock "creates but does NOT send notification to blocker user",
91 blocker = insert(:user)
92 {:ok, _user_relationship} = User.block(blocker, user)
94 {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{blocker.nickname}!"})
96 blocker_id = blocker.id
97 assert [%Notification{user_id: ^blocker_id}] = Repo.all(Notification)
98 refute called(Push.send(:_))
101 test_with_mock "creates but does NOT send notification to notification-muter user",
106 muter = insert(:user)
107 {:ok, _user_relationships} = User.mute(muter, user)
109 {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{muter.nickname}!"})
112 assert [%Notification{user_id: ^muter_id}] = Repo.all(Notification)
113 refute called(Push.send(:_))
116 test_with_mock "creates but does NOT send notification to thread-muter user",
121 thread_muter = insert(:user)
123 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{thread_muter.nickname}!"})
125 {:ok, _} = CommonAPI.add_mute(thread_muter, activity)
127 {:ok, _same_context_activity} =
128 CommonAPI.post(user, %{
129 "status" => "hey-hey-hey @#{thread_muter.nickname}!",
130 "in_reply_to_status_id" => activity.id
133 [pre_mute_notification, post_mute_notification] =
134 Repo.all(from(n in Notification, where: n.user_id == ^thread_muter.id, order_by: n.id))
136 pre_mute_notification_id = pre_mute_notification.id
137 post_mute_notification_id = post_mute_notification.id
142 %Notification{id: ^pre_mute_notification_id} -> true
151 %Notification{id: ^post_mute_notification_id} -> true
159 describe "create_notification" do
160 @tag needs_streamer: true
161 test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
163 task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
164 task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
165 Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
169 %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
172 activity = insert(:note_activity)
174 notify = Notification.create_notification(activity, user)
175 assert notify.user_id == user.id
177 Task.await(task_user_notification)
180 test "it creates a notification for user if the user blocks the activity author" do
181 activity = insert(:note_activity)
182 author = User.get_cached_by_ap_id(activity.data["actor"])
184 {:ok, _user_relationship} = User.block(user, author)
186 assert Notification.create_notification(activity, user)
189 test "it creates a notification for the user if the user mutes the activity author" do
190 muter = insert(:user)
191 muted = insert(:user)
192 {:ok, _} = User.mute(muter, muted)
193 muter = Repo.get(User, muter.id)
194 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
196 assert Notification.create_notification(activity, muter)
199 test "notification created if user is muted without notifications" do
200 muter = insert(:user)
201 muted = insert(:user)
203 {:ok, _user_relationships} = User.mute(muter, muted, false)
205 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
207 assert Notification.create_notification(activity, muter)
210 test "it creates a notification for an activity from a muted thread" do
211 muter = insert(:user)
212 other_user = insert(:user)
213 {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
214 CommonAPI.add_mute(muter, activity)
217 CommonAPI.post(other_user, %{
218 "status" => "Hi @#{muter.nickname}",
219 "in_reply_to_status_id" => activity.id
222 assert Notification.create_notification(activity, muter)
225 test "it disables notifications from followers" do
226 follower = insert(:user)
229 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
231 User.follow(follower, followed)
232 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
233 refute Notification.create_notification(activity, followed)
236 test "it disables notifications from non-followers" do
237 follower = insert(:user)
241 notification_settings: %Pleroma.User.NotificationSetting{non_followers: false}
244 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
245 refute Notification.create_notification(activity, followed)
248 test "it disables notifications from people the user follows" do
250 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{follows: false})
252 followed = insert(:user)
253 User.follow(follower, followed)
254 follower = Repo.get(User, follower.id)
255 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
256 refute Notification.create_notification(activity, follower)
259 test "it disables notifications from people the user does not follow" do
261 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false})
263 followed = insert(:user)
264 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
265 refute Notification.create_notification(activity, follower)
268 test "it doesn't create a notification for user if he is the activity author" do
269 activity = insert(:note_activity)
270 author = User.get_cached_by_ap_id(activity.data["actor"])
272 refute Notification.create_notification(activity, author)
275 test "it doesn't create a notification for follow-unfollow-follow chains" do
277 followed_user = insert(:user)
278 {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
279 Notification.create_notification(activity, followed_user)
280 CommonAPI.unfollow(user, followed_user)
281 {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
282 refute Notification.create_notification(activity_dupe, followed_user)
285 test "it doesn't create duplicate notifications for follow+subscribed users" do
287 subscriber = insert(:user)
289 {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
290 User.subscribe(subscriber, user)
291 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
292 {:ok, [_notif]} = Notification.create_notifications(status)
295 test "it doesn't create subscription notifications if the recipient cannot see the status" do
297 subscriber = insert(:user)
299 User.subscribe(subscriber, user)
301 {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
303 assert {:ok, []} == Notification.create_notifications(status)
307 describe "get notification" do
308 test "it gets a notification that belongs to the user" do
310 other_user = insert(:user)
312 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
314 {:ok, [notification]} = Notification.create_notifications(activity)
315 {:ok, notification} = Notification.get(other_user, notification.id)
317 assert notification.user_id == other_user.id
320 test "it returns error if the notification doesn't belong to the user" do
322 other_user = insert(:user)
324 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
326 {:ok, [notification]} = Notification.create_notifications(activity)
327 {:error, _notification} = Notification.get(user, notification.id)
331 describe "dismiss notification" do
332 test "it dismisses a notification that belongs to the user" do
334 other_user = insert(:user)
336 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
338 {:ok, [notification]} = Notification.create_notifications(activity)
339 {:ok, notification} = Notification.dismiss(other_user, notification.id)
341 assert notification.user_id == other_user.id
344 test "it returns error if the notification doesn't belong to the user" do
346 other_user = insert(:user)
348 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
350 {:ok, [notification]} = Notification.create_notifications(activity)
351 {:error, _notification} = Notification.dismiss(user, notification.id)
355 describe "clear notification" do
356 test "it clears all notifications belonging to the user" do
358 other_user = insert(:user)
359 third_user = insert(:user)
362 CommonAPI.post(user, %{
363 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
366 {:ok, _notifs} = Notification.create_notifications(activity)
369 CommonAPI.post(user, %{
370 "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
373 {:ok, _notifs} = Notification.create_notifications(activity)
374 Notification.clear(other_user)
376 assert Notification.for_user(other_user) == []
377 assert Notification.for_user(third_user) != []
381 describe "set_read_up_to()" do
382 test "it sets all notifications as read up to a specified notification ID" do
384 other_user = insert(:user)
387 CommonAPI.post(user, %{
388 "status" => "hey @#{other_user.nickname}!"
392 CommonAPI.post(user, %{
393 "status" => "hey again @#{other_user.nickname}!"
396 [n2, n1] = notifs = Notification.for_user(other_user)
397 assert length(notifs) == 2
402 CommonAPI.post(user, %{
403 "status" => "hey yet again @#{other_user.nickname}!"
406 Notification.set_read_up_to(other_user, n2.id)
408 [n3, n2, n1] = Notification.for_user(other_user)
410 assert n1.seen == true
411 assert n2.seen == true
412 assert n3.seen == false
416 describe "for_user_since/2" do
417 defp days_ago(days) do
419 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
420 -days * 60 * 60 * 24,
425 test "Returns recent notifications" do
426 user1 = insert(:user)
427 user2 = insert(:user)
429 Enum.each(0..10, fn i ->
431 CommonAPI.post(user1, %{
432 "status" => "hey ##{i} @#{user2.nickname}!"
436 {old, new} = Enum.split(Notification.for_user(user2), 5)
438 Enum.each(old, fn notification ->
440 |> cast(%{updated_at: days_ago(10)}, [:updated_at])
441 |> Pleroma.Repo.update!()
444 recent_notifications_ids =
446 |> Notification.for_user_since(
447 NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
451 Enum.each(old, fn %{id: id} ->
452 refute id in recent_notifications_ids
455 Enum.each(new, fn %{id: id} ->
456 assert id in recent_notifications_ids
461 describe "notification target determination / get_notified_from_activity/2" do
462 test "it sends notifications to addressed users in new messages" do
464 other_user = insert(:user)
467 CommonAPI.post(user, %{
468 "status" => "hey @#{other_user.nickname}!"
471 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
473 assert other_user in enabled_receivers
476 test "it sends notifications to mentioned users in new messages" do
478 other_user = insert(:user)
481 "@context" => "https://www.w3.org/ns/activitystreams",
483 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
484 "actor" => user.ap_id,
487 "content" => "message with a Mention tag, but no explicit tagging",
491 "href" => other_user.ap_id,
492 "name" => other_user.nickname
495 "attributedTo" => user.ap_id
499 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
501 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
503 assert other_user in enabled_receivers
506 test "it does not send notifications to users who are only cc in new messages" do
508 other_user = insert(:user)
511 "@context" => "https://www.w3.org/ns/activitystreams",
513 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
514 "cc" => [other_user.ap_id],
515 "actor" => user.ap_id,
518 "content" => "hi everyone",
519 "attributedTo" => user.ap_id
523 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
525 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
527 assert other_user not in enabled_receivers
530 test "it does not send notification to mentioned users in likes" do
532 other_user = insert(:user)
533 third_user = insert(:user)
535 {:ok, activity_one} =
536 CommonAPI.post(user, %{
537 "status" => "hey @#{other_user.nickname}!"
540 {:ok, activity_two} = CommonAPI.favorite(third_user, activity_one.id)
542 {enabled_receivers, _disabled_receivers} =
543 Notification.get_notified_from_activity(activity_two)
545 assert other_user not in enabled_receivers
548 test "it does not send notification to mentioned users in announces" do
550 other_user = insert(:user)
551 third_user = insert(:user)
553 {:ok, activity_one} =
554 CommonAPI.post(user, %{
555 "status" => "hey @#{other_user.nickname}!"
558 {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
560 {enabled_receivers, _disabled_receivers} =
561 Notification.get_notified_from_activity(activity_two)
563 assert other_user not in enabled_receivers
566 test "it returns blocking recipient in disabled recipients list" do
568 other_user = insert(:user)
569 {:ok, _user_relationship} = User.block(other_user, user)
571 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
573 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
575 assert [] == enabled_receivers
576 assert [other_user] == disabled_receivers
579 test "it returns notification-muting recipient in disabled recipients list" do
581 other_user = insert(:user)
582 {:ok, _user_relationships} = User.mute(other_user, user)
584 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
586 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
588 assert [] == enabled_receivers
589 assert [other_user] == disabled_receivers
592 test "it returns thread-muting recipient in disabled recipients list" do
594 other_user = insert(:user)
596 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
598 {:ok, _} = CommonAPI.add_mute(other_user, activity)
600 {:ok, same_context_activity} =
601 CommonAPI.post(user, %{
602 "status" => "hey-hey-hey @#{other_user.nickname}!",
603 "in_reply_to_status_id" => activity.id
606 {enabled_receivers, disabled_receivers} =
607 Notification.get_notified_from_activity(same_context_activity)
609 assert [other_user] == disabled_receivers
610 refute other_user in enabled_receivers
613 test "it returns domain-blocking recipient in disabled recipients list" do
614 blocked_domain = "blocked.domain"
615 user = insert(:user, %{ap_id: "https://#{blocked_domain}/@actor"})
616 other_user = insert(:user)
618 {:ok, other_user} = User.block_domain(other_user, blocked_domain)
620 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
622 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
624 assert [] == enabled_receivers
625 assert [other_user] == disabled_receivers
629 describe "notification lifecycle" do
630 test "liking an activity results in 1 notification, then 0 if the activity is deleted" do
632 other_user = insert(:user)
634 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
636 assert Enum.empty?(Notification.for_user(user))
638 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
640 assert length(Notification.for_user(user)) == 1
642 {:ok, _} = CommonAPI.delete(activity.id, user)
644 assert Enum.empty?(Notification.for_user(user))
647 test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
649 other_user = insert(:user)
651 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
653 assert Enum.empty?(Notification.for_user(user))
655 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
657 assert length(Notification.for_user(user)) == 1
659 {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
661 assert Enum.empty?(Notification.for_user(user))
664 test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
666 other_user = insert(:user)
668 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
670 assert Enum.empty?(Notification.for_user(user))
672 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
674 assert length(Notification.for_user(user)) == 1
676 {:ok, _} = CommonAPI.delete(activity.id, user)
678 assert Enum.empty?(Notification.for_user(user))
681 test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
683 other_user = insert(:user)
685 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
687 assert Enum.empty?(Notification.for_user(user))
689 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
691 assert length(Notification.for_user(user)) == 1
693 {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
695 assert Enum.empty?(Notification.for_user(user))
698 test "liking an activity which is already deleted does not generate a notification" do
700 other_user = insert(:user)
702 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
704 assert Enum.empty?(Notification.for_user(user))
706 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
708 assert Enum.empty?(Notification.for_user(user))
710 {:error, :not_found} = CommonAPI.favorite(other_user, activity.id)
712 assert Enum.empty?(Notification.for_user(user))
715 test "repeating an activity which is already deleted does not generate a notification" do
717 other_user = insert(:user)
719 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
721 assert Enum.empty?(Notification.for_user(user))
723 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
725 assert Enum.empty?(Notification.for_user(user))
727 {:error, _} = CommonAPI.repeat(activity.id, other_user)
729 assert Enum.empty?(Notification.for_user(user))
732 test "replying to a deleted post without tagging does not generate a notification" do
734 other_user = insert(:user)
736 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
737 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
739 {:ok, _reply_activity} =
740 CommonAPI.post(other_user, %{
741 "status" => "test reply",
742 "in_reply_to_status_id" => activity.id
745 assert Enum.empty?(Notification.for_user(user))
748 test "notifications are deleted if a local user is deleted" do
750 other_user = insert(:user)
753 CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
755 refute Enum.empty?(Notification.for_user(other_user))
757 {:ok, job} = User.delete(user)
758 ObanHelpers.perform(job)
760 assert Enum.empty?(Notification.for_user(other_user))
763 test "notifications are deleted if a remote user is deleted" do
764 remote_user = insert(:user)
765 local_user = insert(:user)
768 "@context" => "https://www.w3.org/ns/activitystreams",
770 "actor" => remote_user.ap_id,
771 "id" => remote_user.ap_id <> "/activities/test",
772 "to" => [local_user.ap_id],
776 "content" => "Hello!",
780 "href" => local_user.ap_id,
781 "name" => "@#{local_user.nickname}"
784 "to" => [local_user.ap_id],
786 "attributedTo" => remote_user.ap_id
790 {:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
792 refute Enum.empty?(Notification.for_user(local_user))
794 delete_user_message = %{
795 "@context" => "https://www.w3.org/ns/activitystreams",
796 "id" => remote_user.ap_id <> "/activities/delete",
797 "actor" => remote_user.ap_id,
799 "object" => remote_user.ap_id
802 remote_user_url = remote_user.ap_id
805 %{method: :get, url: ^remote_user_url} ->
806 %Tesla.Env{status: 404, body: ""}
809 {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
810 ObanHelpers.perform_all()
812 assert Enum.empty?(Notification.for_user(local_user))
815 @tag capture_log: true
816 test "move activity generates a notification" do
817 %{ap_id: old_ap_id} = old_user = insert(:user)
818 %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
819 follower = insert(:user)
820 other_follower = insert(:user, %{allow_following_move: false})
822 User.follow(follower, old_user)
823 User.follow(other_follower, old_user)
825 old_user_url = old_user.ap_id
828 File.read!("test/fixtures/users_mock/localhost.json")
829 |> String.replace("{{nickname}}", old_user.nickname)
833 %{method: :get, url: ^old_user_url} ->
834 %Tesla.Env{status: 200, body: body}
837 Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
838 ObanHelpers.perform_all()
843 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
846 ] = Notification.for_user(follower)
851 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
854 ] = Notification.for_user(other_follower)
858 describe "for_user" do
859 test "it returns notifications for muted user without notifications" do
861 muted = insert(:user)
862 {:ok, _user_relationships} = User.mute(user, muted, false)
864 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
866 assert length(Notification.for_user(user)) == 1
869 test "it doesn't return notifications for muted user with notifications" do
871 muted = insert(:user)
872 {:ok, _user_relationships} = User.mute(user, muted)
874 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
876 assert Notification.for_user(user) == []
879 test "it doesn't return notifications for blocked user" do
881 blocked = insert(:user)
882 {:ok, _user_relationship} = User.block(user, blocked)
884 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
886 assert Notification.for_user(user) == []
889 test "it doesn't return notifications for blocked domain" do
891 blocked = insert(:user, ap_id: "http://some-domain.com")
892 {:ok, user} = User.block_domain(user, "some-domain.com")
894 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
896 assert Notification.for_user(user) == []
899 test "it doesn't return notifications for muted thread" do
901 another_user = insert(:user)
903 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
905 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
906 assert Notification.for_user(user) == []
909 test "it returns notifications from a muted user when with_muted is set" do
911 muted = insert(:user)
912 {:ok, _user_relationships} = User.mute(user, muted)
914 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
916 assert length(Notification.for_user(user, %{with_muted: true})) == 1
919 test "it doesn't return notifications from a blocked user when with_muted is set" do
921 blocked = insert(:user)
922 {:ok, _user_relationship} = User.block(user, blocked)
924 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
926 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
929 test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
931 blocked = insert(:user, ap_id: "http://some-domain.com")
932 {:ok, user} = User.block_domain(user, "some-domain.com")
934 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
936 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
939 test "it returns notifications from muted threads when with_muted is set" do
941 another_user = insert(:user)
943 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
945 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
946 assert length(Notification.for_user(user, %{with_muted: true})) == 1