New mix tasks for controlling user confirmation status and sending confirmation mails
[akkoma] / test / web / streamer / streamer_test.exs
index ffbff35ca32046f6883b20a84b108c929353b27b..d56d7446448e10217d9e921d5db896bb05a92fa8 100644 (file)
@@ -7,6 +7,8 @@ defmodule Pleroma.Web.StreamerTest do
 
   import Pleroma.Factory
 
+  alias Pleroma.Chat
+  alias Pleroma.Chat.MessageReference
   alias Pleroma.Conversation.Participation
   alias Pleroma.List
   alias Pleroma.Object
@@ -114,6 +116,54 @@ defmodule Pleroma.Web.StreamerTest do
       refute Streamer.filtered_by_user?(user, announce)
     end
 
+    test "it does not stream announces of the user's own posts in the 'user' stream", %{
+      user: user
+    } do
+      Streamer.get_topic_and_add_socket("user", user)
+
+      other_user = insert(:user)
+      {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
+      {:ok, announce} = CommonAPI.repeat(activity.id, other_user)
+
+      assert Streamer.filtered_by_user?(user, announce)
+    end
+
+    test "it does stream notifications announces of the user's own posts in the 'user' stream", %{
+      user: user
+    } do
+      Streamer.get_topic_and_add_socket("user", user)
+
+      other_user = insert(:user)
+      {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
+      {:ok, announce} = CommonAPI.repeat(activity.id, other_user)
+
+      notification =
+        Pleroma.Notification
+        |> Repo.get_by(%{user_id: user.id, activity_id: announce.id})
+        |> Repo.preload(:activity)
+
+      refute Streamer.filtered_by_user?(user, notification)
+    end
+
+    test "it streams boosts of mastodon user in the 'user' stream", %{user: user} do
+      Streamer.get_topic_and_add_socket("user", user)
+
+      other_user = insert(:user)
+      {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
+
+      data =
+        File.read!("test/fixtures/mastodon-announce.json")
+        |> Poison.decode!()
+        |> Map.put("object", activity.data["object"])
+        |> Map.put("actor", user.ap_id)
+
+      {:ok, %Pleroma.Activity{data: _data, local: false} = announce} =
+        Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(data)
+
+      assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
+      refute Streamer.filtered_by_user?(user, announce)
+    end
+
     test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
       Streamer.get_topic_and_add_socket("user", user)
       Streamer.stream("user", notify)
@@ -131,22 +181,36 @@ defmodule Pleroma.Web.StreamerTest do
     test "it sends chat messages to the 'user:pleroma_chat' stream", %{user: user} do
       other_user = insert(:user)
 
-      {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey")
+      {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno")
       object = Object.normalize(create_activity, false)
+      chat = Chat.get(user.id, other_user.ap_id)
+      cm_ref = MessageReference.for_chat_and_object(chat, object)
+      cm_ref = %{cm_ref | chat: chat, object: object}
+
       Streamer.get_topic_and_add_socket("user:pleroma_chat", user)
-      Streamer.stream("user:pleroma_chat", object)
-      text = StreamerView.render("chat_update.json", object, user, [user.ap_id, other_user.ap_id])
+      Streamer.stream("user:pleroma_chat", {user, cm_ref})
+
+      text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref})
+
+      assert text =~ "hey cirno"
       assert_receive {:text, ^text}
     end
 
     test "it sends chat messages to the 'user' stream", %{user: user} do
       other_user = insert(:user)
 
-      {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey")
+      {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno")
       object = Object.normalize(create_activity, false)
+      chat = Chat.get(user.id, other_user.ap_id)
+      cm_ref = MessageReference.for_chat_and_object(chat, object)
+      cm_ref = %{cm_ref | chat: chat, object: object}
+
       Streamer.get_topic_and_add_socket("user", user)
-      Streamer.stream("user", object)
-      text = StreamerView.render("chat_update.json", object, user, [user.ap_id, other_user.ap_id])
+      Streamer.stream("user", {user, cm_ref})
+
+      text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref})
+
+      assert text =~ "hey cirno"
       assert_receive {:text, ^text}
     end