defmodule Pleroma.UserTest do
alias Pleroma.Builders.UserBuilder
- alias Pleroma.{User, Repo}
+ alias Pleroma.{User, Repo, Activity}
alias Pleroma.Web.OStatus
alias Pleroma.Web.Websub.WebsubClientSubscription
alias Pleroma.Web.CommonAPI
assert User.ap_followers(followed) in user.following
end
+ test "can't follow a deactivated users" do
+ user = insert(:user)
+ followed = insert(:user, info: %{"deactivated" => true})
+
+ {:error, _} = User.follow(user, followed)
+ end
+
test "following a remote user will ensure a websub subscription is present" do
user = insert(:user)
{:ok, followed} = OStatus.make_user("shp@social.heldscal.la")
assert user in recipients
assert addressed in recipients
end
-end
+ test ".deactivate deactivates a user" do
+ user = insert(:user)
+ assert false == !!user.info["deactivated"]
+ {:ok, user} = User.deactivate(user)
+ assert true == user.info["deactivated"]
+ end
+
+ test ".delete deactivates a user, all follow relationships and all create activities" do
+ user = insert(:user)
+ followed = insert(:user)
+ follower = insert(:user)
+
+ {:ok, user} = User.follow(user, followed)
+ {:ok, follower} = User.follow(follower, user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
+ {:ok, activity_two} = CommonAPI.post(follower, %{"status" => "3hu"})
+
+ {:ok, _, _} = CommonAPI.favorite(activity_two.id, user)
+ {:ok, _, _} = CommonAPI.favorite(activity.id, follower)
+ {:ok, _, _} = CommonAPI.repeat(activity.id, follower)
+
+ :ok = User.delete(user)
+
+ followed = Repo.get(User, followed.id)
+ follower = Repo.get(User, follower.id)
+ user = Repo.get(User, user.id)
+
+ assert user.info["deactivated"]
+
+ refute User.following?(user, followed)
+ refute User.following?(followed, follower)
+
+ # TODO: Remove favorites, repeats, delete activities.
+
+ refute Repo.get(Activity, activity.id)
+ end
+end