Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel
[akkoma] / test / notification_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.NotificationTest do
6 use Pleroma.DataCase
7
8 import Pleroma.Factory
9
10 alias Pleroma.Notification
11 alias Pleroma.Tests.ObanHelpers
12 alias Pleroma.User
13 alias Pleroma.Web.ActivityPub.Transmogrifier
14 alias Pleroma.Web.CommonAPI
15 alias Pleroma.Web.Streamer
16
17 import ExUnit.CaptureLog
18
19 describe "create_notifications" do
20 test "notifies someone when they are directly addressed" do
21 user = insert(:user)
22 other_user = insert(:user)
23 third_user = insert(:user)
24
25 {:ok, activity} =
26 CommonAPI.post(user, %{
27 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
28 })
29
30 {:ok, [notification, other_notification]} = Notification.create_notifications(activity)
31
32 notified_ids = Enum.sort([notification.user_id, other_notification.user_id])
33 assert notified_ids == [other_user.id, third_user.id]
34 assert notification.activity_id == activity.id
35 assert other_notification.activity_id == activity.id
36 end
37
38 test "it creates a notification for subscribed users" do
39 user = insert(:user)
40 subscriber = insert(:user)
41
42 User.subscribe(subscriber, user)
43
44 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
45 {:ok, [notification]} = Notification.create_notifications(status)
46
47 assert notification.user_id == subscriber.id
48 end
49
50 test "does not create a notification for subscribed users if status is a reply" do
51 user = insert(:user)
52 other_user = insert(:user)
53 subscriber = insert(:user)
54
55 User.subscribe(subscriber, other_user)
56
57 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
58
59 {:ok, _reply_activity} =
60 CommonAPI.post(other_user, %{
61 "status" => "test reply",
62 "in_reply_to_status_id" => activity.id
63 })
64
65 user_notifications = Notification.for_user(user)
66 assert length(user_notifications) == 1
67
68 subscriber_notifications = Notification.for_user(subscriber)
69 assert Enum.empty?(subscriber_notifications)
70 end
71 end
72
73 describe "create_notification" do
74 @tag needs_streamer: true
75 test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
76 user = insert(:user)
77 task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
78 task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
79 Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
80
81 Streamer.add_socket(
82 "user:notification",
83 %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
84 )
85
86 activity = insert(:note_activity)
87
88 notify = Notification.create_notification(activity, user)
89 assert notify.user_id == user.id
90 Task.await(task)
91 Task.await(task_user_notification)
92 end
93
94 test "it creates a notification for user if the user blocks the activity author" do
95 activity = insert(:note_activity)
96 author = User.get_cached_by_ap_id(activity.data["actor"])
97 user = insert(:user)
98 {:ok, user} = User.block(user, author)
99
100 assert Notification.create_notification(activity, user)
101 end
102
103 test "it creates a notificatin for the user if the user mutes the activity author" do
104 muter = insert(:user)
105 muted = insert(:user)
106 {:ok, _} = User.mute(muter, muted)
107 muter = Repo.get(User, muter.id)
108 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
109
110 assert Notification.create_notification(activity, muter)
111 end
112
113 test "notification created if user is muted without notifications" do
114 muter = insert(:user)
115 muted = insert(:user)
116
117 {:ok, muter} = User.mute(muter, muted, false)
118
119 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
120
121 assert Notification.create_notification(activity, muter)
122 end
123
124 test "it creates a notification for an activity from a muted thread" do
125 muter = insert(:user)
126 other_user = insert(:user)
127 {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
128 CommonAPI.add_mute(muter, activity)
129
130 {:ok, activity} =
131 CommonAPI.post(other_user, %{
132 "status" => "Hi @#{muter.nickname}",
133 "in_reply_to_status_id" => activity.id
134 })
135
136 assert Notification.create_notification(activity, muter)
137 end
138
139 test "it disables notifications from followers" do
140 follower = insert(:user)
141 followed = insert(:user, notification_settings: %{"followers" => false})
142 User.follow(follower, followed)
143 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
144 refute Notification.create_notification(activity, followed)
145 end
146
147 test "it disables notifications from non-followers" do
148 follower = insert(:user)
149 followed = insert(:user, notification_settings: %{"non_followers" => false})
150 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
151 refute Notification.create_notification(activity, followed)
152 end
153
154 test "it disables notifications from people the user follows" do
155 follower = insert(:user, notification_settings: %{"follows" => false})
156 followed = insert(:user)
157 User.follow(follower, followed)
158 follower = Repo.get(User, follower.id)
159 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
160 refute Notification.create_notification(activity, follower)
161 end
162
163 test "it disables notifications from people the user does not follow" do
164 follower = insert(:user, notification_settings: %{"non_follows" => false})
165 followed = insert(:user)
166 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
167 refute Notification.create_notification(activity, follower)
168 end
169
170 test "it doesn't create a notification for user if he is the activity author" do
171 activity = insert(:note_activity)
172 author = User.get_cached_by_ap_id(activity.data["actor"])
173
174 refute Notification.create_notification(activity, author)
175 end
176
177 test "it doesn't create a notification for follow-unfollow-follow chains" do
178 user = insert(:user)
179 followed_user = insert(:user)
180 {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
181 Notification.create_notification(activity, followed_user)
182 CommonAPI.unfollow(user, followed_user)
183 {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
184 refute Notification.create_notification(activity_dupe, followed_user)
185 end
186
187 test "it doesn't create duplicate notifications for follow+subscribed users" do
188 user = insert(:user)
189 subscriber = insert(:user)
190
191 {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
192 User.subscribe(subscriber, user)
193 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
194 {:ok, [_notif]} = Notification.create_notifications(status)
195 end
196
197 test "it doesn't create subscription notifications if the recipient cannot see the status" do
198 user = insert(:user)
199 subscriber = insert(:user)
200
201 User.subscribe(subscriber, user)
202
203 {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
204
205 assert {:ok, []} == Notification.create_notifications(status)
206 end
207 end
208
209 describe "get notification" do
210 test "it gets a notification that belongs to the user" do
211 user = insert(:user)
212 other_user = insert(:user)
213
214 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
215
216 {:ok, [notification]} = Notification.create_notifications(activity)
217 {:ok, notification} = Notification.get(other_user, notification.id)
218
219 assert notification.user_id == other_user.id
220 end
221
222 test "it returns error if the notification doesn't belong to the user" do
223 user = insert(:user)
224 other_user = insert(:user)
225
226 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
227
228 {:ok, [notification]} = Notification.create_notifications(activity)
229 {:error, _notification} = Notification.get(user, notification.id)
230 end
231 end
232
233 describe "dismiss notification" do
234 test "it dismisses a notification that belongs to the user" do
235 user = insert(:user)
236 other_user = insert(:user)
237
238 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
239
240 {:ok, [notification]} = Notification.create_notifications(activity)
241 {:ok, notification} = Notification.dismiss(other_user, notification.id)
242
243 assert notification.user_id == other_user.id
244 end
245
246 test "it returns error if the notification doesn't belong to the user" do
247 user = insert(:user)
248 other_user = insert(:user)
249
250 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
251
252 {:ok, [notification]} = Notification.create_notifications(activity)
253 {:error, _notification} = Notification.dismiss(user, notification.id)
254 end
255 end
256
257 describe "clear notification" do
258 test "it clears all notifications belonging to the user" do
259 user = insert(:user)
260 other_user = insert(:user)
261 third_user = insert(:user)
262
263 {:ok, activity} =
264 CommonAPI.post(user, %{
265 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
266 })
267
268 {:ok, _notifs} = Notification.create_notifications(activity)
269
270 {:ok, activity} =
271 CommonAPI.post(user, %{
272 "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
273 })
274
275 {:ok, _notifs} = Notification.create_notifications(activity)
276 Notification.clear(other_user)
277
278 assert Notification.for_user(other_user) == []
279 assert Notification.for_user(third_user) != []
280 end
281 end
282
283 describe "set_read_up_to()" do
284 test "it sets all notifications as read up to a specified notification ID" do
285 user = insert(:user)
286 other_user = insert(:user)
287
288 {:ok, _activity} =
289 CommonAPI.post(user, %{
290 "status" => "hey @#{other_user.nickname}!"
291 })
292
293 {:ok, _activity} =
294 CommonAPI.post(user, %{
295 "status" => "hey again @#{other_user.nickname}!"
296 })
297
298 [n2, n1] = notifs = Notification.for_user(other_user)
299 assert length(notifs) == 2
300
301 assert n2.id > n1.id
302
303 {:ok, _activity} =
304 CommonAPI.post(user, %{
305 "status" => "hey yet again @#{other_user.nickname}!"
306 })
307
308 Notification.set_read_up_to(other_user, n2.id)
309
310 [n3, n2, n1] = Notification.for_user(other_user)
311
312 assert n1.seen == true
313 assert n2.seen == true
314 assert n3.seen == false
315 end
316 end
317
318 describe "for_user_since/2" do
319 defp days_ago(days) do
320 NaiveDateTime.add(
321 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
322 -days * 60 * 60 * 24,
323 :second
324 )
325 end
326
327 test "Returns recent notifications" do
328 user1 = insert(:user)
329 user2 = insert(:user)
330
331 Enum.each(0..10, fn i ->
332 {:ok, _activity} =
333 CommonAPI.post(user1, %{
334 "status" => "hey ##{i} @#{user2.nickname}!"
335 })
336 end)
337
338 {old, new} = Enum.split(Notification.for_user(user2), 5)
339
340 Enum.each(old, fn notification ->
341 notification
342 |> cast(%{updated_at: days_ago(10)}, [:updated_at])
343 |> Pleroma.Repo.update!()
344 end)
345
346 recent_notifications_ids =
347 user2
348 |> Notification.for_user_since(
349 NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
350 )
351 |> Enum.map(& &1.id)
352
353 Enum.each(old, fn %{id: id} ->
354 refute id in recent_notifications_ids
355 end)
356
357 Enum.each(new, fn %{id: id} ->
358 assert id in recent_notifications_ids
359 end)
360 end
361 end
362
363 describe "notification target determination" do
364 test "it sends notifications to addressed users in new messages" do
365 user = insert(:user)
366 other_user = insert(:user)
367
368 {:ok, activity} =
369 CommonAPI.post(user, %{
370 "status" => "hey @#{other_user.nickname}!"
371 })
372
373 assert other_user in Notification.get_notified_from_activity(activity)
374 end
375
376 test "it sends notifications to mentioned users in new messages" do
377 user = insert(:user)
378 other_user = insert(:user)
379
380 create_activity = %{
381 "@context" => "https://www.w3.org/ns/activitystreams",
382 "type" => "Create",
383 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
384 "actor" => user.ap_id,
385 "object" => %{
386 "type" => "Note",
387 "content" => "message with a Mention tag, but no explicit tagging",
388 "tag" => [
389 %{
390 "type" => "Mention",
391 "href" => other_user.ap_id,
392 "name" => other_user.nickname
393 }
394 ],
395 "attributedTo" => user.ap_id
396 }
397 }
398
399 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
400
401 assert other_user in Notification.get_notified_from_activity(activity)
402 end
403
404 test "it does not send notifications to users who are only cc in new messages" do
405 user = insert(:user)
406 other_user = insert(:user)
407
408 create_activity = %{
409 "@context" => "https://www.w3.org/ns/activitystreams",
410 "type" => "Create",
411 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
412 "cc" => [other_user.ap_id],
413 "actor" => user.ap_id,
414 "object" => %{
415 "type" => "Note",
416 "content" => "hi everyone",
417 "attributedTo" => user.ap_id
418 }
419 }
420
421 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
422
423 assert other_user not in Notification.get_notified_from_activity(activity)
424 end
425
426 test "it does not send notification to mentioned users in likes" do
427 user = insert(:user)
428 other_user = insert(:user)
429 third_user = insert(:user)
430
431 {:ok, activity_one} =
432 CommonAPI.post(user, %{
433 "status" => "hey @#{other_user.nickname}!"
434 })
435
436 {:ok, activity_two} = CommonAPI.favorite(third_user, activity_one.id)
437
438 assert other_user not in Notification.get_notified_from_activity(activity_two)
439 end
440
441 test "it does not send notification to mentioned users in announces" do
442 user = insert(:user)
443 other_user = insert(:user)
444 third_user = insert(:user)
445
446 {:ok, activity_one} =
447 CommonAPI.post(user, %{
448 "status" => "hey @#{other_user.nickname}!"
449 })
450
451 {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
452
453 assert other_user not in Notification.get_notified_from_activity(activity_two)
454 end
455 end
456
457 describe "notification lifecycle" do
458 test "liking an activity results in 1 notification, then 0 if the activity is deleted" do
459 user = insert(:user)
460 other_user = insert(:user)
461
462 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
463
464 assert Enum.empty?(Notification.for_user(user))
465
466 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
467
468 assert length(Notification.for_user(user)) == 1
469
470 {:ok, _} = CommonAPI.delete(activity.id, user)
471
472 assert Enum.empty?(Notification.for_user(user))
473 end
474
475 test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
476 user = insert(:user)
477 other_user = insert(:user)
478
479 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
480
481 assert Enum.empty?(Notification.for_user(user))
482
483 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
484
485 assert length(Notification.for_user(user)) == 1
486
487 {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
488
489 assert Enum.empty?(Notification.for_user(user))
490 end
491
492 test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
493 user = insert(:user)
494 other_user = insert(:user)
495
496 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
497
498 assert Enum.empty?(Notification.for_user(user))
499
500 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
501
502 assert length(Notification.for_user(user)) == 1
503
504 {:ok, _} = CommonAPI.delete(activity.id, user)
505
506 assert Enum.empty?(Notification.for_user(user))
507 end
508
509 test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
510 user = insert(:user)
511 other_user = insert(:user)
512
513 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
514
515 assert Enum.empty?(Notification.for_user(user))
516
517 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
518
519 assert length(Notification.for_user(user)) == 1
520
521 {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
522
523 assert Enum.empty?(Notification.for_user(user))
524 end
525
526 test "liking an activity which is already deleted does not generate a notification" do
527 user = insert(:user)
528 other_user = insert(:user)
529
530 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
531
532 assert Enum.empty?(Notification.for_user(user))
533
534 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
535
536 assert Enum.empty?(Notification.for_user(user))
537
538 assert capture_log(fn ->
539 {:error, _} = CommonAPI.favorite(other_user, activity.id)
540 end) =~ "[error]"
541
542 assert Enum.empty?(Notification.for_user(user))
543 end
544
545 test "repeating an activity which is already deleted does not generate a notification" do
546 user = insert(:user)
547 other_user = insert(:user)
548
549 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
550
551 assert Enum.empty?(Notification.for_user(user))
552
553 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
554
555 assert Enum.empty?(Notification.for_user(user))
556
557 {:error, _} = CommonAPI.repeat(activity.id, other_user)
558
559 assert Enum.empty?(Notification.for_user(user))
560 end
561
562 test "replying to a deleted post without tagging does not generate a notification" do
563 user = insert(:user)
564 other_user = insert(:user)
565
566 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
567 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
568
569 {:ok, _reply_activity} =
570 CommonAPI.post(other_user, %{
571 "status" => "test reply",
572 "in_reply_to_status_id" => activity.id
573 })
574
575 assert Enum.empty?(Notification.for_user(user))
576 end
577
578 test "notifications are deleted if a local user is deleted" do
579 user = insert(:user)
580 other_user = insert(:user)
581
582 {:ok, _activity} =
583 CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
584
585 refute Enum.empty?(Notification.for_user(other_user))
586
587 {:ok, job} = User.delete(user)
588 ObanHelpers.perform(job)
589
590 assert Enum.empty?(Notification.for_user(other_user))
591 end
592
593 test "notifications are deleted if a remote user is deleted" do
594 remote_user = insert(:user)
595 local_user = insert(:user)
596
597 dm_message = %{
598 "@context" => "https://www.w3.org/ns/activitystreams",
599 "type" => "Create",
600 "actor" => remote_user.ap_id,
601 "id" => remote_user.ap_id <> "/activities/test",
602 "to" => [local_user.ap_id],
603 "cc" => [],
604 "object" => %{
605 "type" => "Note",
606 "content" => "Hello!",
607 "tag" => [
608 %{
609 "type" => "Mention",
610 "href" => local_user.ap_id,
611 "name" => "@#{local_user.nickname}"
612 }
613 ],
614 "to" => [local_user.ap_id],
615 "cc" => [],
616 "attributedTo" => remote_user.ap_id
617 }
618 }
619
620 {:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
621
622 refute Enum.empty?(Notification.for_user(local_user))
623
624 delete_user_message = %{
625 "@context" => "https://www.w3.org/ns/activitystreams",
626 "id" => remote_user.ap_id <> "/activities/delete",
627 "actor" => remote_user.ap_id,
628 "type" => "Delete",
629 "object" => remote_user.ap_id
630 }
631
632 {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
633 ObanHelpers.perform_all()
634
635 assert Enum.empty?(Notification.for_user(local_user))
636 end
637
638 test "move activity generates a notification" do
639 %{ap_id: old_ap_id} = old_user = insert(:user)
640 %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
641 follower = insert(:user)
642 other_follower = insert(:user, %{allow_following_move: false})
643
644 User.follow(follower, old_user)
645 User.follow(other_follower, old_user)
646
647 Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
648 ObanHelpers.perform_all()
649
650 assert [
651 %{
652 activity: %{
653 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
654 }
655 }
656 ] = Notification.for_user(follower)
657
658 assert [
659 %{
660 activity: %{
661 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
662 }
663 }
664 ] = Notification.for_user(other_follower)
665 end
666 end
667
668 describe "for_user" do
669 test "it returns notifications for muted user without notifications" do
670 user = insert(:user)
671 muted = insert(:user)
672 {:ok, user} = User.mute(user, muted, false)
673
674 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
675
676 assert length(Notification.for_user(user)) == 1
677 end
678
679 test "it doesn't return notifications for muted user with notifications" do
680 user = insert(:user)
681 muted = insert(:user)
682 {:ok, user} = User.mute(user, muted)
683
684 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
685
686 assert Notification.for_user(user) == []
687 end
688
689 test "it doesn't return notifications for blocked user" do
690 user = insert(:user)
691 blocked = insert(:user)
692 {:ok, user} = User.block(user, blocked)
693
694 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
695
696 assert Notification.for_user(user) == []
697 end
698
699 test "it doesn't return notificatitons for blocked domain" do
700 user = insert(:user)
701 blocked = insert(:user, ap_id: "http://some-domain.com")
702 {:ok, user} = User.block_domain(user, "some-domain.com")
703
704 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
705
706 assert Notification.for_user(user) == []
707 end
708
709 test "it doesn't return notifications for muted thread" do
710 user = insert(:user)
711 another_user = insert(:user)
712
713 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
714
715 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
716 assert Notification.for_user(user) == []
717 end
718
719 test "it returns notifications from a muted user when with_muted is set" do
720 user = insert(:user)
721 muted = insert(:user)
722 {:ok, user} = User.mute(user, muted)
723
724 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
725
726 assert length(Notification.for_user(user, %{with_muted: true})) == 1
727 end
728
729 test "it doesn't return notifications from a blocked user when with_muted is set" do
730 user = insert(:user)
731 blocked = insert(:user)
732 {:ok, user} = User.block(user, blocked)
733
734 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
735
736 assert length(Notification.for_user(user, %{with_muted: true})) == 0
737 end
738
739 test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
740 user = insert(:user)
741 blocked = insert(:user, ap_id: "http://some-domain.com")
742 {:ok, user} = User.block_domain(user, "some-domain.com")
743
744 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
745
746 assert length(Notification.for_user(user, %{with_muted: true})) == 0
747 end
748
749 test "it returns notifications from muted threads when with_muted is set" do
750 user = insert(:user)
751 another_user = insert(:user)
752
753 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
754
755 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
756 assert length(Notification.for_user(user, %{with_muted: true})) == 1
757 end
758 end
759 end