Merge branch 'hotfix/delete-activities' into 'develop'
[akkoma] / test / web / common_api / common_api_test.exs
index a7d9e61613b6f94785e3cf3298dcc5e4de4cc1e2..181813c76492442fb99ec328ed939e81e642223d 100644 (file)
@@ -2,11 +2,11 @@
 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.Web.CommonAPI.Test do
+defmodule Pleroma.Web.CommonAPITest do
   use Pleroma.DataCase
-  alias Pleroma.Web.CommonAPI
-  alias Pleroma.User
   alias Pleroma.Activity
+  alias Pleroma.User
+  alias Pleroma.Web.CommonAPI
 
   import Pleroma.Factory
 
@@ -164,4 +164,61 @@ defmodule Pleroma.Web.CommonAPI.Test do
       assert %User{info: %{pinned_activities: []}} = user
     end
   end
+
+  describe "mute tests" do
+    setup do
+      user = insert(:user)
+
+      activity = insert(:note_activity)
+
+      [user: user, activity: activity]
+    end
+
+    test "add mute", %{user: user, activity: activity} do
+      {:ok, _} = CommonAPI.add_mute(user, activity)
+      assert CommonAPI.thread_muted?(user, activity)
+    end
+
+    test "remove mute", %{user: user, activity: activity} do
+      CommonAPI.add_mute(user, activity)
+      {:ok, _} = CommonAPI.remove_mute(user, activity)
+      refute CommonAPI.thread_muted?(user, activity)
+    end
+
+    test "check that mutes can't be duplicate", %{user: user, activity: activity} do
+      CommonAPI.add_mute(user, activity)
+      {:error, _} = CommonAPI.add_mute(user, activity)
+    end
+  end
+
+  describe "reports" do
+    test "creates a report" do
+      reporter = insert(:user)
+      target_user = insert(:user)
+
+      {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+
+      reporter_ap_id = reporter.ap_id
+      target_ap_id = target_user.ap_id
+      activity_ap_id = activity.data["id"]
+      comment = "foobar"
+
+      report_data = %{
+        "account_id" => target_user.id,
+        "comment" => comment,
+        "status_ids" => [activity.id]
+      }
+
+      assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
+
+      assert %Activity{
+               actor: ^reporter_ap_id,
+               data: %{
+                 "type" => "Flag",
+                 "content" => ^comment,
+                 "object" => [^target_ap_id, ^activity_ap_id]
+               }
+             } = flag_activity
+    end
+  end
 end