add tests
This commit is contained in:
parent
46bd5c1d87
commit
dd097a406b
2 changed files with 75 additions and 12 deletions
|
@ -1159,13 +1159,16 @@ def perform(:deactivate_async, user, status), do: deactivate(user, status)
|
|||
def deactivate(%User{} = user, status \\ true) do
|
||||
info_cng = User.Info.set_activation_status(user.info, status)
|
||||
|
||||
with {:ok, user} <-
|
||||
with {:ok, friends} <- User.get_friends(user),
|
||||
{:ok, followers} <- User.get_followers(user),
|
||||
{:ok, user} <-
|
||||
user
|
||||
|> change()
|
||||
|> put_embed(:info, info_cng)
|
||||
|> update_and_set_cache(),
|
||||
{:ok, friends} <- User.get_friends(user) do
|
||||
|> update_and_set_cache() do
|
||||
Enum.each(followers, &invalidate_cache(&1))
|
||||
Enum.each(friends, &update_follower_count(&1))
|
||||
|
||||
{:ok, user}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
defmodule Pleroma.UserTest do
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Builders.UserBuilder
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
use Pleroma.DataCase
|
||||
|
@ -212,8 +214,8 @@ test "test if a user is following another user" do
|
|||
test "fetches correct profile for nickname beginning with number" do
|
||||
# Use old-style integer ID to try to reproduce the problem
|
||||
user = insert(:user, %{id: 1080})
|
||||
userwithnumbers = insert(:user, %{nickname: "#{user.id}garbage"})
|
||||
assert userwithnumbers == User.get_cached_by_nickname_or_id(userwithnumbers.nickname)
|
||||
user_with_numbers = insert(:user, %{nickname: "#{user.id}garbage"})
|
||||
assert user_with_numbers == User.get_cached_by_nickname_or_id(user_with_numbers.nickname)
|
||||
end
|
||||
|
||||
describe "user registration" do
|
||||
|
@ -815,7 +817,8 @@ test "get recipients from activity" do
|
|||
assert addressed in recipients
|
||||
end
|
||||
|
||||
test ".deactivate can de-activate then re-activate a user" do
|
||||
describe ".deactivate" do
|
||||
test "can de-activate then re-activate a user" do
|
||||
user = insert(:user)
|
||||
assert false == user.info.deactivated
|
||||
{:ok, user} = User.deactivate(user)
|
||||
|
@ -824,6 +827,63 @@ test ".deactivate can de-activate then re-activate a user" do
|
|||
assert false == user.info.deactivated
|
||||
end
|
||||
|
||||
test "hide a user from followers " do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, user2)
|
||||
{:ok, _user} = User.deactivate(user)
|
||||
|
||||
info = User.get_cached_user_info(user2)
|
||||
|
||||
assert info.follower_count == 0
|
||||
assert {:ok, []} = User.get_followers(user2)
|
||||
end
|
||||
|
||||
test "hide a user from friends" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, user2} = User.follow(user2, user)
|
||||
assert User.following_count(user2) == 1
|
||||
|
||||
{:ok, _user} = User.deactivate(user)
|
||||
|
||||
info = User.get_cached_user_info(user2)
|
||||
|
||||
assert info.following_count == 0
|
||||
assert User.following_count(user2) == 0
|
||||
assert {:ok, []} = User.get_friends(user2)
|
||||
end
|
||||
|
||||
test "hide a user's statuses from timelines and notifications" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, user2} = User.follow(user2, user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
|
||||
|
||||
[notification] = Notification.for_user(user2)
|
||||
assert notification.activity == activity
|
||||
|
||||
assert [activity] == ActivityPub.fetch_public_activities(%{})
|
||||
|
||||
assert [activity] ==
|
||||
ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
|
||||
|> ActivityPub.contain_timeline(user2)
|
||||
|
||||
{:ok, _user} = User.deactivate(user)
|
||||
|
||||
assert [] == ActivityPub.fetch_public_activities(%{})
|
||||
assert [] == Notification.for_user(user2)
|
||||
|
||||
assert [] ==
|
||||
ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
|
||||
|> ActivityPub.contain_timeline(user2)
|
||||
end
|
||||
end
|
||||
|
||||
test ".delete_user_activities deletes all create activities" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
Loading…
Reference in a new issue