Merge branch 'develop' into feature/polls-2-electric-boogalo
[akkoma] / test / notification_test.exs
index 5727620c9b5fe41bcb327085b2fe60cc30176559..be292abd9ffce0e6cef082965aa1e1fce4dd2733 100644 (file)
@@ -46,16 +46,72 @@ defmodule Pleroma.NotificationTest do
   describe "create_notification" do
     test "it doesn't create a notification for user if the user blocks the activity author" do
       activity = insert(:note_activity)
-      author = User.get_by_ap_id(activity.data["actor"])
+      author = User.get_cached_by_ap_id(activity.data["actor"])
       user = insert(:user)
       {:ok, user} = User.block(user, author)
 
       assert nil == Notification.create_notification(activity, user)
     end
 
+    test "it doesn't create a notificatin for the user if the user mutes the activity author" do
+      muter = insert(:user)
+      muted = insert(:user)
+      {:ok, _} = User.mute(muter, muted)
+      muter = Repo.get(User, muter.id)
+      {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
+
+      assert nil == Notification.create_notification(activity, muter)
+    end
+
+    test "it doesn't create a notification for an activity from a muted thread" do
+      muter = insert(:user)
+      other_user = insert(:user)
+      {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
+      CommonAPI.add_mute(muter, activity)
+
+      {:ok, activity} =
+        CommonAPI.post(other_user, %{
+          "status" => "Hi @#{muter.nickname}",
+          "in_reply_to_status_id" => activity.id
+        })
+
+      assert nil == Notification.create_notification(activity, muter)
+    end
+
+    test "it disables notifications from followers" do
+      follower = insert(:user)
+      followed = insert(:user, info: %{notification_settings: %{"followers" => false}})
+      User.follow(follower, followed)
+      {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
+      assert nil == Notification.create_notification(activity, followed)
+    end
+
+    test "it disables notifications from non-followers" do
+      follower = insert(:user)
+      followed = insert(:user, info: %{notification_settings: %{"non_followers" => false}})
+      {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
+      assert nil == Notification.create_notification(activity, followed)
+    end
+
+    test "it disables notifications from people the user follows" do
+      follower = insert(:user, info: %{notification_settings: %{"follows" => false}})
+      followed = insert(:user)
+      User.follow(follower, followed)
+      follower = Repo.get(User, follower.id)
+      {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
+      assert nil == Notification.create_notification(activity, follower)
+    end
+
+    test "it disables notifications from people the user does not follow" do
+      follower = insert(:user, info: %{notification_settings: %{"non_follows" => false}})
+      followed = insert(:user)
+      {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
+      assert nil == Notification.create_notification(activity, follower)
+    end
+
     test "it doesn't create a notification for user if he is the activity author" do
       activity = insert(:note_activity)
-      author = User.get_by_ap_id(activity.data["actor"])
+      author = User.get_cached_by_ap_id(activity.data["actor"])
 
       assert nil == Notification.create_notification(activity, author)
     end