+ {:ok, user} = User.deactivate(user, false)
+ assert false == !!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
+
+ test "get_public_key_for_ap_id fetches a user that's not in the db" do
+ assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
+ end
+
+ test "insert or update a user from given data" do
+ user = insert(:user, %{nickname: "nick@name.de"})
+ data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
+
+ describe "per-user rich-text filtering" do
+ test "html_filter_policy returns nil when rich-text is enabled" do
+ user = insert(:user)
+
+ assert nil == User.html_filter_policy(user)
+ end
+
+ test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
+ user = insert(:user, %{info: %{"no_rich_text" => true}})
+
+ assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
+ end
+ end
+
+ describe "caching" do
+ test "invalidate_cache works" do
+ user = insert(:user)
+ user_info = User.get_cached_user_info(user)
+
+ User.invalidate_cache(user)
+
+ {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
+ {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
+ {:ok, nil} = Cachex.get(:user_cache, "user_info:#{user.id}")
+ end
+
+ test "User.delete() plugs any possible zombie objects" do
+ user = insert(:user)
+
+ {:ok, _} = User.delete(user)
+
+ {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
+
+ assert cached_user != user
+
+ {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
+
+ assert cached_user != user
+ end
+ end
+
+ describe "User.search" do
+ test "finds a user, ranking by similarity" do
+ user = insert(:user, %{name: "lain"})
+ user_two = insert(:user, %{name: "ean"})
+ user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"})
+ user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"})
+
+ assert user_four ==
+ User.search("lain@ple") |> List.first() |> Map.put(:search_distance, nil)
+ end