aboutsummaryrefslogtreecommitdiff
path: root/test/pleroma/web/common_api_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/pleroma/web/common_api_test.exs')
-rw-r--r--test/pleroma/web/common_api_test.exs124
1 files changed, 124 insertions, 0 deletions
diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs
index f5d09f396..a5d395558 100644
--- a/test/pleroma/web/common_api_test.exs
+++ b/test/pleroma/web/common_api_test.exs
@@ -1241,4 +1241,128 @@ defmodule Pleroma.Web.CommonAPITest do
} = CommonAPI.get_user("")
end
end
+
+ describe "with `local_only` enabled" do
+ setup do: clear_config([:instance, :federating], true)
+
+ test "post" do
+ user = insert(:user)
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU", local_only: true})
+
+ assert Activity.local_only?(activity)
+ assert_not_called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+
+ test "delete" do
+ user = insert(:user)
+
+ {:ok, %Activity{id: activity_id}} =
+ CommonAPI.post(user, %{status: "#2hu #2HU", local_only: true})
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ assert {:ok, %Activity{data: %{"deleted_activity_id" => ^activity_id}} = activity} =
+ CommonAPI.delete(activity_id, user)
+
+ assert Activity.local_only?(activity)
+ assert_not_called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+
+ test "repeat" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, %Activity{id: activity_id}} =
+ CommonAPI.post(other_user, %{status: "cofe", local_only: true})
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ assert {:ok, %Activity{data: %{"type" => "Announce"}} = activity} =
+ CommonAPI.repeat(activity_id, user)
+
+ assert Activity.local_only?(activity)
+ refute called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+
+ test "unrepeat" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, %Activity{id: activity_id}} =
+ CommonAPI.post(other_user, %{status: "cofe", local_only: true})
+
+ assert {:ok, _} = CommonAPI.repeat(activity_id, user)
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
+ CommonAPI.unrepeat(activity_id, user)
+
+ assert Activity.local_only?(activity)
+ refute called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+
+ test "favorite" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", local_only: true})
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ assert {:ok, %Activity{data: %{"type" => "Like"}} = activity} =
+ CommonAPI.favorite(user, activity.id)
+
+ assert Activity.local_only?(activity)
+ refute called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+
+ test "unfavorite" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", local_only: true})
+
+ {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ assert {:ok, activity} = CommonAPI.unfavorite(activity.id, user)
+ assert Activity.local_only?(activity)
+ refute called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+
+ test "react_with_emoji" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", local_only: true})
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ assert {:ok, %Activity{data: %{"type" => "EmojiReact"}} = activity} =
+ CommonAPI.react_with_emoji(activity.id, user, "👍")
+
+ assert Activity.local_only?(activity)
+ refute called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+
+ test "unreact_with_emoji" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", local_only: true})
+
+ {:ok, _reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
+
+ with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
+ assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
+ CommonAPI.unreact_with_emoji(activity.id, user, "👍")
+
+ assert Activity.local_only?(activity)
+ refute called(Pleroma.Web.Federator.publish(activity))
+ end
+ end
+ end
end