Merge branch 'bugfix/1543-streaming-boosts' into 'develop'
[akkoma] / test / web / streamer / streamer_test.exs
index ad8ce030b1f49c82e79b1947298bcff56683e8b8..8b8d8af6c51521dac9046715814c22d24fcc6731 100644 (file)
@@ -28,6 +28,42 @@ defmodule Pleroma.Web.StreamerTest do
       {:ok, %{user: user, notify: notify}}
     end
 
+    test "it streams the user's post in the 'user' stream", %{user: user} do
+      task =
+        Task.async(fn ->
+          assert_receive {:text, _}, @streamer_timeout
+        end)
+
+      Streamer.add_socket(
+        "user",
+        %{transport_pid: task.pid, assigns: %{user: user}}
+      )
+
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+
+      Streamer.stream("user", activity)
+      Task.await(task)
+    end
+
+    test "it streams boosts of the user in the 'user' stream", %{user: user} do
+      task =
+        Task.async(fn ->
+          assert_receive {:text, _}, @streamer_timeout
+        end)
+
+      Streamer.add_socket(
+        "user",
+        %{transport_pid: task.pid, assigns: %{user: user}}
+      )
+
+      other_user = insert(:user)
+      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
+      {:ok, announce, _} = CommonAPI.repeat(activity.id, user)
+
+      Streamer.stream("user", announce)
+      Task.await(task)
+    end
+
     test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
       task =
         Task.async(fn ->
@@ -64,9 +100,6 @@ defmodule Pleroma.Web.StreamerTest do
       blocked = insert(:user)
       {:ok, _user_relationship} = User.block(user, blocked)
 
-      {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
-      {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
-
       task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end)
 
       Streamer.add_socket(
@@ -74,6 +107,9 @@ defmodule Pleroma.Web.StreamerTest do
         %{transport_pid: task.pid, assigns: %{user: user}}
       )
 
+      {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
+      {:ok, notif} = CommonAPI.favorite(blocked, activity.id)
+
       Streamer.stream("user:notification", notif)
       Task.await(task)
     end
@@ -83,10 +119,6 @@ defmodule Pleroma.Web.StreamerTest do
     } do
       user2 = insert(:user)
 
-      {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
-      {:ok, activity} = CommonAPI.add_mute(user, activity)
-      {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
-
       task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end)
 
       Streamer.add_socket(
@@ -94,6 +126,10 @@ defmodule Pleroma.Web.StreamerTest do
         %{transport_pid: task.pid, assigns: %{user: user}}
       )
 
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+      {:ok, activity} = CommonAPI.add_mute(user, activity)
+      {:ok, notif} = CommonAPI.favorite(user2, activity.id)
+
       Streamer.stream("user:notification", notif)
       Task.await(task)
     end
@@ -103,10 +139,6 @@ defmodule Pleroma.Web.StreamerTest do
     } do
       user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
 
-      {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
-      {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
-      {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
-
       task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end)
 
       Streamer.add_socket(
@@ -114,6 +146,10 @@ defmodule Pleroma.Web.StreamerTest do
         %{transport_pid: task.pid, assigns: %{user: user}}
       )
 
+      {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+      {:ok, notif} = CommonAPI.favorite(user2, activity.id)
+
       Streamer.stream("user:notification", notif)
       Task.await(task)
     end
@@ -121,6 +157,18 @@ defmodule Pleroma.Web.StreamerTest do
     test "it sends follow activities to the 'user:notification' stream", %{
       user: user
     } do
+      user_url = user.ap_id
+
+      body =
+        File.read!("test/fixtures/users_mock/localhost.json")
+        |> String.replace("{{nickname}}", user.nickname)
+        |> Jason.encode!()
+
+      Tesla.Mock.mock_global(fn
+        %{method: :get, url: ^user_url} ->
+          %Tesla.Env{status: 200, body: body}
+      end)
+
       user2 = insert(:user)
       task = Task.async(fn -> assert_receive {:text, _}, @streamer_timeout end)
 
@@ -464,7 +512,7 @@ defmodule Pleroma.Web.StreamerTest do
     CommonAPI.hide_reblogs(user1, user2)
 
     {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
-    {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, user2)
+    {:ok, favorite_activity} = CommonAPI.favorite(user2, create_activity.id)
 
     task =
       Task.async(fn ->