# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UserTest do
+ alias Pleroma.Repo
alias Pleroma.User
use Pleroma.DataCase
assert_received {:mix_shell, :info, [message]}
assert message =~ "created"
- user = User.get_by_nickname(unsaved.nickname)
+ user = User.get_cached_by_nickname(unsaved.nickname)
assert user.name == unsaved.name
assert user.email == unsaved.email
assert user.bio == unsaved.bio
assert_received {:mix_shell, :info, [message]}
assert message =~ "will not be created"
- refute User.get_by_nickname(unsaved.nickname)
+ refute User.get_cached_by_nickname(unsaved.nickname)
end
end
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ " deactivated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ " activated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ "Successfully unsubscribed"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(user.following)
assert user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* true/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.is_moderator
assert user.info.locked
assert user.info.is_admin
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* false/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.is_moderator
refute user.info.locked
refute user.info.is_admin
assert message =~ "Generated user invite token one time"
end
- test "token is generated with expire_at" do
+ test "token is generated with expires_at" do
assert capture_io(fn ->
Mix.Tasks.Pleroma.User.run([
"invite",
- "--expire-date",
+ "--expires-at",
Date.to_string(Date.utc_today())
])
end)
assert message =~ "Generated user invite token reusable"
end
- test "token is generated with max use and expire date" do
+ test "token is generated with max use and expires date" do
assert capture_io(fn ->
Mix.Tasks.Pleroma.User.run([
"invite",
"--max-use",
"5",
- "--expire-date",
+ "--expires-at",
Date.to_string(Date.utc_today())
])
end)
end
end
- describe "running invites_list" do
+ describe "running invites" do
test "invites are listed" do
{:ok, invite} = Pleroma.UserInviteToken.create_invite()
{:ok, invite2} =
- Pleroma.UserInviteToken.create_invite(%{expire_at: Date.utc_today(), max_use: 15})
+ Pleroma.UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 15})
- assert capture_io(fn ->
- Mix.Tasks.Pleroma.User.run([
- "invites_list"
- ])
- end)
+ # assert capture_io(fn ->
+ Mix.Tasks.Pleroma.User.run([
+ "invites"
+ ])
+
+ # end)
assert_received {:mix_shell, :info, [message]}
assert_received {:mix_shell, :info, [message2]}
end
end
- describe "running invite revoke" do
+ describe "running revoke_invite" do
test "invite is revoked" do
- {:ok, invite} = Pleroma.UserInviteToken.create_invite(%{expire_at: Date.utc_today()})
+ {:ok, invite} = Pleroma.UserInviteToken.create_invite(%{expires_at: Date.utc_today()})
assert capture_io(fn ->
Mix.Tasks.Pleroma.User.run([
- "invite_revoke",
+ "revoke_invite",
invite.token
])
end)
assert message == "User #{nickname} statuses deleted."
end
end
+
+ describe "running toggle_confirmed" do
+ test "user is confirmed" do
+ %{id: id, nickname: nickname} = insert(:user, info: %{confirmation_pending: false})
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "#{nickname} needs confirmation."
+
+ user = Repo.get(User, id)
+ assert user.info.confirmation_pending
+ assert user.info.confirmation_token
+ end
+
+ test "user is not confirmed" do
+ %{id: id, nickname: nickname} =
+ insert(:user, info: %{confirmation_pending: true, confirmation_token: "some token"})
+
+ assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "#{nickname} doesn't need confirmation."
+
+ user = Repo.get(User, id)
+ refute user.info.confirmation_pending
+ refute user.info.confirmation_token
+ end
+ end
+
+ describe "search" do
+ test "it returns users matching" do
+ user = insert(:user)
+ moon = insert(:user, nickname: "moon", name: "fediverse expert moon")
+ moot = insert(:user, nickname: "moot")
+ kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
+
+ {:ok, user} = User.follow(user, kawen)
+
+ assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
+ res = User.search("moo") |> Enum.map(& &1.id)
+ assert moon.id in res
+ assert moot.id in res
+ assert kawen.id in res
+ assert [moon.id, kawen.id] == User.Search.search("moon fediverse") |> Enum.map(& &1.id)
+
+ assert [kawen.id, moon.id] ==
+ User.Search.search("moon fediverse", for_user: user) |> Enum.map(& &1.id)
+ end
+ end
end