Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / test / web / common_api / common_api_test.exs
index 1984aac8d1bd06acb436a575a5d7a21107311524..86b3648ac2f05806707e67955f4c082da818e565 100644 (file)
@@ -23,6 +23,8 @@ defmodule Pleroma.Web.CommonAPITest do
   setup do: clear_config([:instance, :max_pinned_statuses])
 
   describe "posting chat messages" do
+    setup do: clear_config([:instance, :chat_limit])
+
     test "it posts a chat message" do
       author = insert(:user)
       recipient = insert(:user)
@@ -31,7 +33,7 @@ defmodule Pleroma.Web.CommonAPITest do
         CommonAPI.post_chat_message(
           author,
           recipient,
-          "a test message <script>alert('uuu')</script>"
+          "a test message <script>alert('uuu')</script> :firefox:"
         )
 
       assert activity.data["type"] == "Create"
@@ -42,11 +44,31 @@ defmodule Pleroma.Web.CommonAPITest do
       assert object.data["to"] == [recipient.ap_id]
 
       assert object.data["content"] ==
-               "a test message &lt;script&gt;alert(&#39;uuu&#39;)&lt;/script&gt;"
+               "a test message &lt;script&gt;alert(&#39;uuu&#39;)&lt;/script&gt; :firefox:"
+
+      assert object.data["emoji"] == %{
+               "firefox" => "http://localhost:4001/emoji/Firefox.gif"
+             }
 
       assert Chat.get(author.id, recipient.ap_id)
       assert Chat.get(recipient.id, author.ap_id)
     end
+
+    test "it reject messages over the local limit" do
+      Pleroma.Config.put([:instance, :chat_limit], 2)
+
+      author = insert(:user)
+      recipient = insert(:user)
+
+      {:error, message} =
+        CommonAPI.post_chat_message(
+          author,
+          recipient,
+          "123"
+        )
+
+      assert message == :content_too_long
+    end
   end
 
   test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do