X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fstreamer%2Fstreamer_test.exs;h=3c0f240f54168daaa4e91e8567f0bdb00be04a13;hb=473b0d9f3d500fae6e7afb3884d4872d7033e6fc;hp=1cf20f1c2a56597e96b7327a58f80ee8f045efb8;hpb=292031f6dd809accbcb3a5ba59d0100d807c5d72;p=akkoma
diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs
index 1cf20f1c2..3c0f240f5 100644
--- a/test/web/streamer/streamer_test.exs
+++ b/test/web/streamer/streamer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.StreamerTest do
@@ -19,8 +19,7 @@ defmodule Pleroma.Web.StreamerTest do
@streamer_timeout 150
@streamer_start_wait 10
-
- clear_config([:instance, :skip_thread_containment])
+ setup do: clear_config([:instance, :skip_thread_containment])
describe "user streams" do
setup do
@@ -29,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 ->
@@ -65,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(
@@ -75,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
@@ -84,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(
@@ -95,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
@@ -104,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(
@@ -115,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
@@ -122,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)
@@ -163,6 +210,12 @@ defmodule Pleroma.Web.StreamerTest do
Worker.push_to_socket(topics, "public", activity)
Task.await(task)
+ end
+
+ test "works for deletions" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
task =
Task.async(fn ->
@@ -198,7 +251,7 @@ defmodule Pleroma.Web.StreamerTest do
Pleroma.Config.put([:instance, :skip_thread_containment], false)
author = insert(:user)
user = insert(:user)
- User.follow(user, author, "accept")
+ User.follow(user, author, :follow_accept)
activity =
insert(:note_activity,
@@ -221,7 +274,7 @@ defmodule Pleroma.Web.StreamerTest do
Pleroma.Config.put([:instance, :skip_thread_containment], true)
author = insert(:user)
user = insert(:user)
- User.follow(user, author, "accept")
+ User.follow(user, author, :follow_accept)
activity =
insert(:note_activity,
@@ -244,7 +297,7 @@ defmodule Pleroma.Web.StreamerTest do
Pleroma.Config.put([:instance, :skip_thread_containment], false)
author = insert(:user)
user = insert(:user, skip_thread_containment: true)
- User.follow(user, author, "accept")
+ User.follow(user, author, :follow_accept)
activity =
insert(:note_activity,
@@ -465,7 +518,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 ->