InstanceView: Add chat limit, description limit
[akkoma] / test / notification_test.exs
index 6bc2b6904b5972025b48c59d5898a1ad9cc9fcd0..6add3f7eba39c9cc4287fcc2c62a6717e13981d6 100644 (file)
@@ -10,6 +10,7 @@ defmodule Pleroma.NotificationTest do
 
   alias Pleroma.FollowingRelationship
   alias Pleroma.Notification
+  alias Pleroma.Repo
   alias Pleroma.Tests.ObanHelpers
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
@@ -20,35 +21,17 @@ defmodule Pleroma.NotificationTest do
   alias Pleroma.Web.Push
   alias Pleroma.Web.Streamer
 
-  describe "fill_in_notification_types" do
-    test "it fills in missing notification types" do
+  describe "create_notifications" do
+    test "never returns nil" do
       user = insert(:user)
-      other_user = insert(:user)
-
-      {:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"})
-      {:ok, chat} = CommonAPI.post_chat_message(user, other_user, "yo")
-      {:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
-      {:ok, like} = CommonAPI.favorite(other_user, post.id)
-
-      assert {4, nil} = Repo.update_all(Notification, set: [type: nil])
+      other_user = insert(:user, %{invisible: true})
 
-      Notification.fill_in_notification_types()
-
-      assert %{type: "mention"} =
-               Repo.get_by(Notification, user_id: other_user.id, activity_id: post.id)
-
-      assert %{type: "favourite"} =
-               Repo.get_by(Notification, user_id: user.id, activity_id: like.id)
-
-      assert %{type: "pleroma:emoji_reaction"} =
-               Repo.get_by(Notification, user_id: user.id, activity_id: react.id)
+      {:ok, activity} = CommonAPI.post(user, %{status: "yeah"})
+      {:ok, activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
 
-      assert %{type: "pleroma:chat_mention"} =
-               Repo.get_by(Notification, user_id: other_user.id, activity_id: chat.id)
+      refute {:ok, [nil]} == Notification.create_notifications(activity)
     end
-  end
 
-  describe "create_notifications" do
     test "creates a notification for an emoji reaction" do
       user = insert(:user)
       other_user = insert(:user)
@@ -333,6 +316,14 @@ defmodule Pleroma.NotificationTest do
 
       assert {:ok, []} == Notification.create_notifications(status)
     end
+
+    test "it disables notifications from people who are invisible" do
+      author = insert(:user, invisible: true)
+      user = insert(:user)
+
+      {:ok, status} = CommonAPI.post(author, %{status: "hey @#{user.nickname}"})
+      refute Notification.create_notification(status, user)
+    end
   end
 
   describe "follow / follow_request notifications" do