Merge branch 'develop' into global-status-expiration
[akkoma] / test / web / mastodon_api / controllers / timeline_controller_test.exs
index a15c759d4ecdfc7ad5f2a35264b3a41f9a80c633..97b1c3e66c35b06d82d1488d1b3b89b0a6f19f6f 100644 (file)
@@ -21,9 +21,12 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
     setup do: oauth_access(["read:statuses"])
 
     test "the home timeline", %{user: user, conn: conn} do
-      following = insert(:user)
+      following = insert(:user, nickname: "followed")
+      third_user = insert(:user, nickname: "repeated")
 
-      {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
+      {: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, "/api/v1/timelines/home")
 
@@ -31,9 +34,54 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
 
       {:ok, _user} = User.follow(user, following)
 
-      conn = get(conn, "/api/v1/timelines/home")
+      ret_conn = get(conn, "/api/v1/timelines/home")
+
+      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(ret_conn, :ok)
+
+      {:ok, _user} = User.follow(third_user, user)
 
-      assert [%{"content" => "test"}] = json_response(conn, :ok)
+      ret_conn = get(conn, "/api/v1/timelines/home")
+
+      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(ret_conn, :ok)
     end
 
     test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
@@ -100,13 +148,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
   describe "public with restrict unauthenticated timeline for local and federated timelines" do
     setup do: local_and_remote_activities()
 
-    clear_config([:restrict_unauthenticated, :timelines, :local]) do
-      Config.put([:restrict_unauthenticated, :timelines, :local], true)
-    end
+    setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
 
-    clear_config([:restrict_unauthenticated, :timelines, :federated]) do
-      Config.put([:restrict_unauthenticated, :timelines, :federated], true)
-    end
+    setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
 
     test "if user is unauthenticated", %{conn: conn} do
       res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
@@ -136,9 +180,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
   describe "public with restrict unauthenticated timeline for local" do
     setup do: local_and_remote_activities()
 
-    clear_config([:restrict_unauthenticated, :timelines, :local]) do
-      Config.put([:restrict_unauthenticated, :timelines, :local], true)
-    end
+    setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
 
     test "if user is unauthenticated", %{conn: conn} do
       res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
@@ -165,9 +207,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
   describe "public with restrict unauthenticated timeline for remote" do
     setup do: local_and_remote_activities()
 
-    clear_config([:restrict_unauthenticated, :timelines, :federated]) do
-      Config.put([:restrict_unauthenticated, :timelines, :federated], true)
-    end
+    setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
 
     test "if user is unauthenticated", %{conn: conn} do
       res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})