def run(["deactivate", nickname]) do
start_pleroma()
- with %User{} = user <- User.get_cached_by_nickname(nickname) do
- shell_info("Deactivating #{user.nickname}")
+ with %User{} = user <- User.get_cached_by_nickname(nickname),
+ true <- user.is_active do
User.set_activation(user, false)
:timer.sleep(500)
user = User.get_cached_by_id(user.id)
if Enum.empty?(Enum.filter(User.get_friends(user), & &1.local)) do
- shell_info("Successfully unsubscribed all local followers from #{user.nickname}")
+ shell_info("Successfully deactivated #{nickname} and unsubscribed all local followers")
end
else
+ false ->
+ shell_info("User #{nickname} already deactivated")
+
_ ->
shell_error("No user #{nickname}")
end
end
describe "running deactivate" do
- test "user is unsubscribed" do
+ test "active user is deactivated and unsubscribed" do
followed = insert(:user)
remote_followed = insert(:user, local: false)
user = insert(:user)
Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Deactivating"
-
# Note that the task has delay :timer.sleep(500)
assert_received {:mix_shell, :info, [message]}
- assert message =~ "Successfully unsubscribed"
+
+ assert message ==
+ "Successfully deactivated #{user.nickname} and unsubscribed all local followers"
user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
refute user.is_active
end
+ test "user is deactivated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: false)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["deactivate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "User #{nickname} already deactivated"
+
+ user = Repo.get(User, id)
+ refute user.is_active
+ end
+
test "no user to deactivate" do
Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"])
assert user.is_active
end
- test "it prints an error message when user is not exist" do
+ test "no user to activate" do
Mix.Tasks.Pleroma.User.run(["activate", "foo"])
assert_received {:mix_shell, :error, [message]}