Merge branch 'develop' into 'cleanup/masto_fe-default_settings'
[akkoma] / test / web / pleroma_api / controllers / chat_controller_test.exs
index c2960956dbdfab5a77bfc01f57474fc45c454d49..d71e80d03ca37799d3664f9b79068f1730f2d2b8 100644 (file)
@@ -289,7 +289,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
       assert length(result) == 0
     end
 
-    test "it paginates", %{conn: conn, user: user} do
+    test "it returns all chats", %{conn: conn, user: user} do
       Enum.each(1..30, fn _ ->
         recipient = insert(:user)
         {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
@@ -300,14 +300,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
         |> get("/api/v1/pleroma/chats")
         |> json_response_and_validate_schema(200)
 
-      assert length(result) == 20
-
-      result =
-        conn
-        |> get("/api/v1/pleroma/chats?max_id=#{List.last(result)["id"]}")
-        |> json_response_and_validate_schema(200)
-
-      assert length(result) == 10
+      assert length(result) == 30
     end
 
     test "it return a list of chats the current user is participating in, in descending order of updates",
@@ -339,5 +332,27 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
                chat_1.id |> to_string()
              ]
     end
+
+    test "it is not affected by :restrict_unauthenticated setting (issue #1973)", %{
+      conn: conn,
+      user: user
+    } do
+      clear_config([:restrict_unauthenticated, :profiles, :local], true)
+      clear_config([:restrict_unauthenticated, :profiles, :remote], true)
+
+      user2 = insert(:user)
+      user3 = insert(:user, local: false)
+
+      {:ok, _chat_12} = Chat.get_or_create(user.id, user2.ap_id)
+      {:ok, _chat_13} = Chat.get_or_create(user.id, user3.ap_id)
+
+      result =
+        conn
+        |> get("/api/v1/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
+      assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
+    end
   end
 end