+ test "get recipients from activity" do
+ actor = insert(:user)
+ user = insert(:user, local: true)
+ user_two = insert(:user, local: false)
+ addressed = insert(:user, local: true)
+ addressed_remote = insert(:user, local: false)
+ {:ok, activity} = CommonAPI.post(actor, %{"status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"})
+
+ assert [addressed] == User.get_recipients_from_activity(activity)
+
+ {:ok, user} = User.follow(user, actor)
+ {:ok, user_two} = User.follow(user_two, actor)
+ recipients = User.get_recipients_from_activity(activity)
+ assert length(recipients) == 2
+ assert user in recipients
+ assert addressed in recipients
+ 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