Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into feature/expire...
[akkoma] / test / pleroma / web / common_api_test.exs
similarity index 97%
rename from test/web/common_api/common_api_test.exs
rename to test/pleroma/web/common_api_test.exs
index 45ab1e0bdf2949ab3fdbf220c1c1bcbd7009bd49..8e87e69fe0a3b4f84ab70a52d3eb95950d03e5d7 100644 (file)
@@ -29,6 +29,23 @@ defmodule Pleroma.Web.CommonAPITest do
   setup do: clear_config([:instance, :limit])
   setup do: clear_config([:instance, :max_pinned_statuses])
 
+  describe "posting polls" do
+    test "it posts a poll" do
+      user = insert(:user)
+
+      {:ok, activity} =
+        CommonAPI.post(user, %{
+          status: "who is the best",
+          poll: %{expires_in: 600, options: ["reimu", "marisa"]}
+        })
+
+      object = Object.normalize(activity)
+
+      assert object.data["type"] == "Question"
+      assert object.data["oneOf"] |> length() == 2
+    end
+  end
+
   describe "blocking" do
     setup do
       blocker = insert(:user)
@@ -78,12 +95,26 @@ defmodule Pleroma.Web.CommonAPITest do
   describe "posting chat messages" do
     setup do: clear_config([:instance, :chat_limit])
 
+    test "it posts a self-chat" do
+      author = insert(:user)
+      recipient = author
+
+      {:ok, activity} =
+        CommonAPI.post_chat_message(
+          author,
+          recipient,
+          "remember to buy milk when milk truk arive"
+        )
+
+      assert activity.data["type"] == "Create"
+    end
+
     test "it posts a chat message without content but with an attachment" do
       author = insert(:user)
       recipient = insert(:user)
 
       file = %Plug.Upload{
-        content_type: "image/jpg",
+        content_type: "image/jpeg",
         path: Path.absname("test/fixtures/image.jpg"),
         filename: "an_image.jpg"
       }
@@ -605,7 +636,7 @@ defmodule Pleroma.Web.CommonAPITest do
       assert {:error, "The status is over the character limit"} =
                CommonAPI.post(user, %{status: "foobar"})
 
-      assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
+      assert {:ok, _activity} = CommonAPI.post(user, %{status: "12345"})
     end
 
     test "it can handle activities that expire" do
@@ -1076,7 +1107,7 @@ defmodule Pleroma.Web.CommonAPITest do
 
     test "cancels a pending follow for a local user" do
       follower = insert(:user)
-      followed = insert(:user, locked: true)
+      followed = insert(:user, is_locked: true)
 
       assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
                CommonAPI.follow(follower, followed)
@@ -1098,7 +1129,7 @@ defmodule Pleroma.Web.CommonAPITest do
 
     test "cancels a pending follow for a remote user" do
       follower = insert(:user)
-      followed = insert(:user, locked: true, local: false, ap_enabled: true)
+      followed = insert(:user, is_locked: true, local: false, ap_enabled: true)
 
       assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
                CommonAPI.follow(follower, followed)
@@ -1121,7 +1152,7 @@ defmodule Pleroma.Web.CommonAPITest do
 
   describe "accept_follow_request/2" do
     test "after acceptance, it sets all existing pending follow request states to 'accept'" do
-      user = insert(:user, locked: true)
+      user = insert(:user, is_locked: true)
       follower = insert(:user)
       follower_two = insert(:user)
 
@@ -1141,7 +1172,7 @@ defmodule Pleroma.Web.CommonAPITest do
     end
 
     test "after rejection, it sets all existing pending follow request states to 'reject'" do
-      user = insert(:user, locked: true)
+      user = insert(:user, is_locked: true)
       follower = insert(:user)
       follower_two = insert(:user)
 
@@ -1161,7 +1192,7 @@ defmodule Pleroma.Web.CommonAPITest do
     end
 
     test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
-      user = insert(:user, locked: true)
+      user = insert(:user, is_locked: true)
       not_follower = insert(:user)
       CommonAPI.accept_follow_request(not_follower, user)