X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fmix%2Ftasks%2Fpleroma%2Fuser_test.exs;h=a2178bbd1137b965fa089f5b2b3cd6d340865c20;hb=e56c319e8f4c121c5a3c014ac0b2e3567bfa636b;hp=be0cb2668f6ada116fa9d0af31c4ab1dc7cb94e8;hpb=35ba48494f5129d3a0010b045ff36d98e7e7984f;p=akkoma
diff --git a/test/mix/tasks/pleroma/user_test.exs b/test/mix/tasks/pleroma/user_test.exs
index be0cb2668..a2178bbd1 100644
--- a/test/mix/tasks/pleroma/user_test.exs
+++ b/test/mix/tasks/pleroma/user_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UserTest do
@@ -36,7 +36,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
unsaved = build(:user)
# prepare to answer yes
- send(self(), {:mix_shell_input, :yes?, true})
+ send(self(), {:mix_shell_input, :prompt, "Y"})
Mix.Tasks.Pleroma.User.run([
"new",
@@ -55,7 +55,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "user will be created"
- assert_received {:mix_shell, :yes?, [message]}
+ assert_received {:mix_shell, :prompt, [message]}
assert message =~ "Continue"
assert_received {:mix_shell, :info, [message]}
@@ -73,14 +73,14 @@ defmodule Mix.Tasks.Pleroma.UserTest do
unsaved = build(:user)
# prepare to answer no
- send(self(), {:mix_shell_input, :yes?, false})
+ send(self(), {:mix_shell_input, :prompt, "N"})
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_received {:mix_shell, :prompt, [message]}
assert message =~ "Continue"
assert_received {:mix_shell, :info, [message]}
@@ -102,7 +102,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+ assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_))
end
@@ -114,7 +114,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
{:ok, post} = CommonAPI.post(user, %{status: "uguu"})
{:ok, post2} = CommonAPI.post(user2, %{status: "test"})
- obj = Object.normalize(post2)
+ obj = Object.normalize(post2, fetch: false)
{:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj)
@@ -130,7 +130,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
clear_config([:instance, :federating], true)
- object = Object.normalize(post)
+ object = Object.normalize(post, fetch: false)
Object.prune(object)
with_mock Pleroma.Web.Federator,
@@ -140,7 +140,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+ assert %{is_active: false} = User.get_by_nickname(user.nickname)
assert called(Pleroma.Web.Federator.publish(:_))
refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
@@ -157,41 +157,8 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
- describe "running toggle_activated" do
- test "user is deactivated" do
- user = insert(:user)
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " deactivated"
-
- user = User.get_cached_by_nickname(user.nickname)
- assert user.deactivated
- end
-
- test "user is activated" do
- user = insert(:user, deactivated: true)
-
- Mix.Tasks.Pleroma.User.run(["toggle_activated", user.nickname])
-
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " activated"
-
- user = User.get_cached_by_nickname(user.nickname)
- refute user.deactivated
- end
-
- test "no user to toggle" do
- Mix.Tasks.Pleroma.User.run(["toggle_activated", "nonexistent"])
-
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No user"
- 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)
@@ -201,16 +168,26 @@ defmodule Mix.Tasks.Pleroma.UserTest do
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))
- assert user.deactivated
+ 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
@@ -238,7 +215,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ ~r/Admin status .* true/
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r/Confirmation pending .* false/
+ assert message =~ ~r/Confirmation status.* true/
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* true/
@@ -250,7 +227,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert user.is_moderator
assert user.is_locked
assert user.is_admin
- refute user.confirmation_pending
+ assert user.is_confirmed
end
test "All statuses unset" do
@@ -259,7 +236,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
is_locked: true,
is_moderator: true,
is_admin: true,
- confirmation_pending: true
+ is_confirmed: false
)
Mix.Tasks.Pleroma.User.run([
@@ -275,7 +252,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ ~r/Admin status .* false/
assert_received {:mix_shell, :info, [message]}
- assert message =~ ~r/Confirmation pending .* true/
+ assert message =~ ~r/Confirmation status.* false/
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* false/
@@ -287,7 +264,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
refute user.is_moderator
refute user.is_locked
refute user.is_admin
- assert user.confirmation_pending
+ refute user.is_confirmed
end
test "no user to set status" do
@@ -436,13 +413,6 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "Invite for token #{invite.token} was revoked."
end
-
- test "it prints an error message when invite is not exist" do
- Mix.Tasks.Pleroma.User.run(["revoke_invite", "foo"])
-
- assert_received {:mix_shell, :error, [message]}
- assert message =~ "No invite found"
- end
end
describe "running delete_activities" do
@@ -462,40 +432,71 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
- describe "running toggle_confirmed" do
+ describe "running confirm" do
test "user is confirmed" do
- %{id: id, nickname: nickname} = insert(:user, confirmation_pending: false)
+ %{id: id, nickname: nickname} = insert(:user, is_confirmed: true)
- assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
+ assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]}
- assert message == "#{nickname} needs confirmation."
+ assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id)
- assert user.confirmation_pending
- assert user.confirmation_token
+ assert user.is_confirmed
+ refute user.confirmation_token
end
test "user is not confirmed" do
%{id: id, nickname: nickname} =
- insert(:user, confirmation_pending: true, confirmation_token: "some token")
+ insert(:user, is_confirmed: false, confirmation_token: "some token")
- assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
+ assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]}
assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id)
- refute user.confirmation_pending
+ assert user.is_confirmed
refute user.confirmation_token
end
test "it prints an error message when user is not exist" do
- Mix.Tasks.Pleroma.User.run(["toggle_confirmed", "foo"])
+ Mix.Tasks.Pleroma.User.run(["confirm", "foo"])
assert_received {:mix_shell, :error, [message]}
assert message =~ "No local user"
end
end
+ describe "running activate" do
+ test "user is activated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: true)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "User #{nickname} already activated"
+
+ user = Repo.get(User, id)
+ assert user.is_active
+ end
+
+ test "user is not activated" do
+ %{id: id, nickname: nickname} = insert(:user, is_active: false)
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "Successfully activated #{nickname}"
+
+ user = Repo.get(User, id)
+ assert user.is_active
+ end
+
+ test "no user to activate" do
+ Mix.Tasks.Pleroma.User.run(["activate", "foo"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No user"
+ end
+ end
+
describe "search" do
test "it returns users matching" do
user = insert(:user)
@@ -579,29 +580,29 @@ defmodule Mix.Tasks.Pleroma.UserTest do
describe "bulk confirm and unconfirm" do
test "confirm all" do
- user1 = insert(:user, confirmation_pending: true)
- user2 = insert(:user, confirmation_pending: true)
+ user1 = insert(:user, is_confirmed: false)
+ user2 = insert(:user, is_confirmed: false)
- assert user1.confirmation_pending
- assert user2.confirmation_pending
+ refute user1.is_confirmed
+ refute user2.is_confirmed
Mix.Tasks.Pleroma.User.run(["confirm_all"])
user1 = User.get_cached_by_nickname(user1.nickname)
user2 = User.get_cached_by_nickname(user2.nickname)
- refute user1.confirmation_pending
- refute user2.confirmation_pending
+ assert user1.is_confirmed
+ assert user2.is_confirmed
end
test "unconfirm all" do
- user1 = insert(:user, confirmation_pending: false)
- user2 = insert(:user, confirmation_pending: false)
- admin = insert(:user, is_admin: true, confirmation_pending: false)
- mod = insert(:user, is_moderator: true, confirmation_pending: false)
+ user1 = insert(:user, is_confirmed: true)
+ user2 = insert(:user, is_confirmed: true)
+ admin = insert(:user, is_admin: true, is_confirmed: true)
+ mod = insert(:user, is_moderator: true, is_confirmed: true)
- refute user1.confirmation_pending
- refute user2.confirmation_pending
+ assert user1.is_confirmed
+ assert user2.is_confirmed
Mix.Tasks.Pleroma.User.run(["unconfirm_all"])
@@ -610,10 +611,10 @@ defmodule Mix.Tasks.Pleroma.UserTest do
admin = User.get_cached_by_nickname(admin.nickname)
mod = User.get_cached_by_nickname(mod.nickname)
- assert user1.confirmation_pending
- assert user2.confirmation_pending
- refute admin.confirmation_pending
- refute mod.confirmation_pending
+ refute user1.is_confirmed
+ refute user2.is_confirmed
+ assert admin.is_confirmed
+ assert mod.is_confirmed
end
end
end