--- /dev/null
+defmodule Mix.Tasks.Pleroma.RelayTest do
+ alias Pleroma.Activity
+ alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils}
+ alias Pleroma.User
+ use Pleroma.DataCase
+
+ setup_all do
+ Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "running follow" do
+ test "relay is followed" do
+ target_instance = "http://mastodon.example.org/users/admin"
+
+ Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
+
+ local_user = Relay.get_actor()
+ assert local_user.ap_id =~ "/relay"
+
+ target_user = User.get_by_ap_id(target_instance)
+ refute target_user.local
+
+ activity = Utils.fetch_latest_follow(local_user, target_user)
+ assert activity.data["type"] == "Follow"
+ assert activity.data["actor"] == local_user.ap_id
+ assert activity.data["object"] == target_user.ap_id
+ end
+ end
+
+ describe "running unfollow" do
+ test "relay is unfollowed" do
+ target_instance = "http://mastodon.example.org/users/admin"
+
+ Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
+
+ %User{ap_id: follower_id} = local_user = Relay.get_actor()
+ target_user = User.get_by_ap_id(target_instance)
+ follow_activity = Utils.fetch_latest_follow(local_user, target_user)
+
+ Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
+
+ cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
+ assert cancelled_activity.data["state"] == "cancelled"
+
+ [undo_activity] =
+ ActivityPub.fetch_activities([], %{
+ "type" => "Undo",
+ "actor_id" => follower_id,
+ "limit" => 1
+ })
+
+ assert undo_activity.data["type"] == "Undo"
+ assert undo_activity.data["actor"] == local_user.ap_id
+ assert undo_activity.data["object"] == cancelled_activity.data
+ end
+ end
+end
--- /dev/null
+defmodule Mix.Tasks.Pleroma.UploadsTest do
+ alias Pleroma.Upload
+ use Pleroma.DataCase
+
+ import Mock
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ describe "running migrate_local" do
+ test "uploads migrated" do
+ with_mock Upload,
+ store: fn %Upload{name: _file, path: _path}, _opts -> {:ok, %{}} end do
+ Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "S3"])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ "Migrating files from local"
+
+ assert_received {:mix_shell, :info, [message]}
+
+ assert %{"total_count" => total_count} =
+ Regex.named_captures(~r"^Found (?<total_count>\d+) uploads$", message)
+
+ assert_received {:mix_shell, :info, [message]}
+
+ assert %{"count" => ^total_count, "total_count" => ^total_count} =
+ Regex.named_captures(
+ ~r"^Uploaded (?<count>\d+)/(?<total_count>\d+) files$",
+ message
+ )
+ end
+ end
+
+ test "nonexistent uploader" do
+ assert_raise RuntimeError, ~r/The uploader .* is not an existing/, fn ->
+ Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "nonexistent"])
+ end
+ end
+ end
+end
assert_received {:mix_shell, :info, [message]}
assert message =~ "user will be created"
+
assert_received {:mix_shell, :yes?, [message]}
assert message =~ "Continue"
+
assert_received {:mix_shell, :info, [message]}
assert message =~ "created"
# prepare to answer no
send(self(), {:mix_shell_input, :yes?, false})
+
Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email])
+
assert_received {:mix_shell, :info, [message]}
assert message =~ "user will be created"
+
assert_received {:mix_shell, :yes?, [message]}
assert message =~ "Continue"
+
assert_received {:mix_shell, :info, [message]}
assert message =~ "will not be created"
user = insert(:user)
Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
+
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
end
test "no user to delete" do
- Mix.Tasks.Pleroma.User.run(["rm", "nonexistant"])
+ Mix.Tasks.Pleroma.User.run(["rm", "nonexistent"])
+
assert_received {:mix_shell, :error, [message]}
assert message =~ "No local user"
end
user = insert(:user)
Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
+
assert_received {:mix_shell, :info, [message]}
assert message =~ " deactivated"
user = insert(:user, info: %{deactivated: true})
Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
+
assert_received {:mix_shell, :info, [message]}
assert message =~ " activated"
end
test "no user to toggle" do
- Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistant"])
+ Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistent"])
+
assert_received {:mix_shell, :error, [message]}
assert message =~ "No user"
end
user = insert(:user, %{following: [User.ap_followers(followed)]})
Mix.Tasks.Pleroma.User.run(["unsubscribe", user.nickname])
+
assert_received {:mix_shell, :info, [message]}
assert message =~ "Deactivating"
+
assert_received {:mix_shell, :info, [message]}
assert message =~ "Unsubscribing"
+
# Note that the task has delay :timer.sleep(500)
assert_received {:mix_shell, :info, [message]}
assert message =~ "Successfully unsubscribed"
end
test "no user to unsubscribe" do
- Mix.Tasks.Pleroma.User.run(["unsubscribe", "nonexistant"])
+ Mix.Tasks.Pleroma.User.run(["unsubscribe", "nonexistent"])
+
assert_received {:mix_shell, :error, [message]}
assert message =~ "No user"
end
user = insert(:user)
Mix.Tasks.Pleroma.User.run(["set", user.nickname, "--moderator", "--admin", "--locked"])
+
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Moderator status .* true"
+ assert message =~ ~r/Moderator status .* true/
+
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Locked status .* true"
+ assert message =~ ~r/Locked status .* true/
+
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Admin status .* true"
+ assert message =~ ~r/Admin status .* true/
user = User.get_by_nickname(user.nickname)
assert user.info.is_moderator
])
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Moderator status .* false"
+ assert message =~ ~r/Moderator status .* false/
+
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Locked status .* false"
+ assert message =~ ~r/Locked status .* false/
+
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r"Admin status .* false"
+ assert message =~ ~r/Admin status .* false/
user = User.get_by_nickname(user.nickname)
refute user.info.is_moderator
end
test "no user to set status" do
- Mix.Tasks.Pleroma.User.run(["set", "nonexistant", "--moderator"])
+ Mix.Tasks.Pleroma.User.run(["set", "nonexistent", "--moderator"])
+
assert_received {:mix_shell, :error, [message]}
assert message =~ "No local user"
end
end
test "no user to reset password" do
- Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistant"])
+ Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"])
+
assert_received {:mix_shell, :error, [message]}
assert message =~ "No local user"
end