Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / test / web / pleroma_api / controllers / chat_controller_test.exs
index 6b2db5064307c455182c17480c26c25f549a0acb..dad37a889b57ec967664eb1a86bee0c743c067b6 100644 (file)
@@ -9,11 +9,27 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
 
   import Pleroma.Factory
 
+  describe "POST /api/v1/pleroma/chats/:id/messages" do
+    test "it posts a message to the chat", %{conn: conn} do
+      user = insert(:user)
+      other_user = insert(:user)
+
+      {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id)
+
+      result =
+        conn
+        |> assign(:user, user)
+        |> post("/api/v1/pleroma/chats/#{chat.id}/messages", %{"content" => "Hallo!!"})
+        |> json_response(200)
+
+      assert result["content"] == "Hallo!!"
+      assert result["chat_id"] == chat.id
+    end
+  end
+
   describe "GET /api/v1/pleroma/chats/:id/messages" do
     # TODO
-    # - Test that statuses don't show
     # - Test the case where it's not the user's chat
-    # - Test the returned data
     test "it returns the messages for a given chat", %{conn: conn} do
       user = insert(:user)
       other_user = insert(:user)
@@ -32,6 +48,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
         |> get("/api/v1/pleroma/chats/#{chat.id}/messages")
         |> json_response(200)
 
+      result
+      |> Enum.each(fn message ->
+        assert message["chat_id"] == chat.id
+      end)
+
       assert length(result) == 3
     end
   end