Merge branch 'develop' into activation-meta
[akkoma] / test / web / mastodon_api / controllers / timeline_controller_test.exs
index 5e0d92f28ace6f94bcdfd60091bc81b6bdf37fc8..f069390c11aca746b8b0acf11898199cf72e9d68 100644 (file)
@@ -20,15 +20,13 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
   describe "home" do
     setup do: oauth_access(["read:statuses"])
 
-    test "does NOT render account/pleroma/relationship if this is disabled by default", %{
+    test "does NOT embed account/pleroma/relationship in statuses", %{
       user: user,
       conn: conn
     } do
-      clear_config([:extensions, :output_relationships_in_statuses_by_default], false)
-
       other_user = insert(:user)
 
-      {:ok, _} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+      {:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
 
       response =
         conn
@@ -41,81 +39,13 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
              end)
     end
 
-    test "the home timeline", %{user: user, conn: conn} do
-      uri = "/api/v1/timelines/home?with_relationships=1"
-
-      following = insert(:user, nickname: "followed")
-      third_user = insert(:user, nickname: "repeated")
-
-      {:ok, _activity} = CommonAPI.post(following, %{"status" => "post"})
-      {:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"})
-      {:ok, _, _} = CommonAPI.repeat(activity.id, following)
-
-      ret_conn = get(conn, uri)
-
-      assert Enum.empty?(json_response_and_validate_schema(ret_conn, :ok))
-
-      {:ok, _user} = User.follow(user, following)
-
-      ret_conn = get(conn, uri)
-
-      assert [
-               %{
-                 "reblog" => %{
-                   "content" => "repeated post",
-                   "account" => %{
-                     "pleroma" => %{
-                       "relationship" => %{"following" => false, "followed_by" => false}
-                     }
-                   }
-                 },
-                 "account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
-               },
-               %{
-                 "content" => "post",
-                 "account" => %{
-                   "acct" => "followed",
-                   "pleroma" => %{"relationship" => %{"following" => true}}
-                 }
-               }
-             ] = json_response_and_validate_schema(ret_conn, :ok)
-
-      {:ok, _user} = User.follow(third_user, user)
-
-      ret_conn = get(conn, uri)
-
-      assert [
-               %{
-                 "reblog" => %{
-                   "content" => "repeated post",
-                   "account" => %{
-                     "acct" => "repeated",
-                     "pleroma" => %{
-                       "relationship" => %{"following" => false, "followed_by" => true}
-                     }
-                   }
-                 },
-                 "account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
-               },
-               %{
-                 "content" => "post",
-                 "account" => %{
-                   "acct" => "followed",
-                   "pleroma" => %{"relationship" => %{"following" => true}}
-                 }
-               }
-             ] = json_response_and_validate_schema(ret_conn, :ok)
-    end
-
     test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
-      {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
-      {:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+      {:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
+      {:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
 
-      {:ok, unlisted_activity} =
-        CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
+      {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
 
-      {:ok, private_activity} =
-        CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+      {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
 
       conn = get(conn, "/api/v1/timelines/home?exclude_visibilities[]=direct")
 
@@ -130,9 +60,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
   describe "public" do
     @tag capture_log: true
     test "the public timeline", %{conn: conn} do
-      following = insert(:user)
+      user = insert(:user)
 
-      {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
+      {:ok, activity} = CommonAPI.post(user, %{status: "test"})
 
       _activity = insert(:note_activity, local: false)
 
@@ -147,19 +77,69 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       conn = get(build_conn(), "/api/v1/timelines/public?local=1")
 
       assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
+
+      # does not contain repeats
+      {:ok, _} = CommonAPI.repeat(activity.id, user)
+
+      conn = get(build_conn(), "/api/v1/timelines/public?local=true")
+
+      assert [_] = json_response_and_validate_schema(conn, :ok)
     end
 
     test "the public timeline includes only public statuses for an authenticated user" do
       %{user: user, conn: conn} = oauth_access(["read:statuses"])
 
-      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test"})
-      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"})
-      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"})
-      {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
+      {:ok, _activity} = CommonAPI.post(user, %{status: "test"})
+      {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"})
+      {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"})
+      {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
 
       res_conn = get(conn, "/api/v1/timelines/public")
       assert length(json_response_and_validate_schema(res_conn, 200)) == 1
     end
+
+    test "doesn't return replies if follower is posting with blocked user" do
+      %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
+      [blockee, friend] = insert_list(2, :user)
+      {:ok, blocker} = User.follow(blocker, friend)
+      {:ok, _} = User.block(blocker, blockee)
+
+      conn = assign(conn, :user, blocker)
+
+      {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
+
+      {:ok, reply_from_blockee} =
+        CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
+
+      {:ok, _reply_from_friend} =
+        CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
+
+      res_conn = get(conn, "/api/v1/timelines/public")
+      [%{"id" => ^activity_id}] = json_response_and_validate_schema(res_conn, 200)
+    end
+
+    test "doesn't return replies if follow is posting with users from blocked domain" do
+      %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
+      friend = insert(:user)
+      blockee = insert(:user, ap_id: "https://example.com/users/blocked")
+      {:ok, blocker} = User.follow(blocker, friend)
+      {:ok, blocker} = User.block_domain(blocker, "example.com")
+
+      conn = assign(conn, :user, blocker)
+
+      {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
+
+      {:ok, reply_from_blockee} =
+        CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
+
+      {:ok, _reply_from_friend} =
+        CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
+
+      res_conn = get(conn, "/api/v1/timelines/public")
+
+      activities = json_response_and_validate_schema(res_conn, 200)
+      [%{"id" => ^activity_id}] = activities
+    end
   end
 
   defp local_and_remote_activities do
@@ -263,14 +243,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
 
       {:ok, direct} =
         CommonAPI.post(user_one, %{
-          "status" => "Hi @#{user_two.nickname}!",
-          "visibility" => "direct"
+          status: "Hi @#{user_two.nickname}!",
+          visibility: "direct"
         })
 
       {:ok, _follower_only} =
         CommonAPI.post(user_one, %{
-          "status" => "Hi @#{user_two.nickname}!",
-          "visibility" => "private"
+          status: "Hi @#{user_two.nickname}!",
+          visibility: "private"
         })
 
       conn_user_two =
@@ -306,8 +286,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       Enum.each(1..20, fn _ ->
         {:ok, _} =
           CommonAPI.post(user_one, %{
-            "status" => "Hi @#{user_two.nickname}!",
-            "visibility" => "direct"
+            status: "Hi @#{user_two.nickname}!",
+            visibility: "direct"
           })
       end)
 
@@ -333,14 +313,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
 
       {:ok, _blocked_direct} =
         CommonAPI.post(blocked, %{
-          "status" => "Hi @#{blocker.nickname}!",
-          "visibility" => "direct"
+          status: "Hi @#{blocker.nickname}!",
+          visibility: "direct"
         })
 
       {:ok, direct} =
         CommonAPI.post(other_user, %{
-          "status" => "Hi @#{blocker.nickname}!",
-          "visibility" => "direct"
+          status: "Hi @#{blocker.nickname}!",
+          visibility: "direct"
         })
 
       res_conn = get(conn, "api/v1/timelines/direct")
@@ -355,8 +335,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
 
     test "list timeline", %{user: user, conn: conn} do
       other_user = insert(:user)
-      {:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."})
-      {:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
+      {:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
+      {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
       {:ok, list} = Pleroma.List.create("name", user)
       {:ok, list} = Pleroma.List.follow(list, other_user)
 
@@ -372,12 +352,12 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       conn: conn
     } do
       other_user = insert(:user)
-      {:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
+      {:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
 
       {:ok, _activity_two} =
         CommonAPI.post(other_user, %{
-          "status" => "Marisa is cute.",
-          "visibility" => "private"
+          status: "Marisa is cute.",
+          visibility: "private"
         })
 
       {:ok, list} = Pleroma.List.create("name", user)
@@ -398,7 +378,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
     test "hashtag timeline", %{conn: conn} do
       following = insert(:user)
 
-      {:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
+      {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
 
       nconn = get(conn, "/api/v1/timelines/tag/2hu")
 
@@ -417,9 +397,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
     test "multi-hashtag timeline", %{conn: conn} do
       user = insert(:user)
 
-      {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
-      {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
-      {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
+      {:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
+      {:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
+      {:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
 
       any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1")