Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / test / web / pleroma_api / controllers / chat_controller_test.exs
index 75d4903ed74f7361d913632fa2ba308e39bfa8cf..d79aa3148d4b391a578a63bcfff554730e055180 100644 (file)
@@ -4,8 +4,9 @@
 defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
   use Pleroma.Web.ConnCase, async: true
 
-  alias Pleroma.Object
   alias Pleroma.Chat
+  alias Pleroma.Object
+  alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.CommonAPI
 
@@ -52,6 +53,20 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
       assert result["chat_id"] == chat.id |> to_string()
     end
 
+    test "it fails if there is no content", %{conn: conn, user: user} do
+      other_user = insert(:user)
+
+      {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
+
+      result =
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/v1/pleroma/chats/#{chat.id}/messages")
+        |> json_response_and_validate_schema(400)
+
+      assert result
+    end
+
     test "it works with an attachment", %{conn: conn, user: user} do
       file = %Plug.Upload{
         content_type: "image/jpg",
@@ -69,13 +84,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
         conn
         |> put_req_header("content-type", "application/json")
         |> post("/api/v1/pleroma/chats/#{chat.id}/messages", %{
-          "content" => "Hallo!!",
           "media_id" => to_string(upload.id)
         })
         |> json_response_and_validate_schema(200)
 
-      assert result["content"] == "Hallo!!"
-      assert result["chat_id"] == chat.id |> to_string()
+      assert result["attachment"]
     end
   end
 
@@ -209,6 +222,28 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
   describe "GET /api/v1/pleroma/chats" do
     setup do: oauth_access(["read:statuses"])
 
+    test "it does not return chats with users you blocked", %{conn: conn, user: user} do
+      recipient = insert(:user)
+
+      {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+
+      result =
+        conn
+        |> get("/api/v1/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 1
+
+      User.block(user, recipient)
+
+      result =
+        conn
+        |> get("/api/v1/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 0
+    end
+
     test "it paginates", %{conn: conn, user: user} do
       Enum.each(1..30, fn _ ->
         recipient = insert(:user)