+ } = AccountView.render("show.json", %{user: user, for: user})
+ end
+
+ test "shows unread_conversation_count only to the account owner" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(other_user, %{
+ "status" => "Hey @#{user.nickname}.",
+ "visibility" => "direct"
+ })
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert AccountView.render("show.json", %{user: user, for: other_user})[:pleroma][
+ :unread_conversation_count
+ ] == nil
+
+ assert AccountView.render("show.json", %{user: user, for: user})[:pleroma][
+ :unread_conversation_count
+ ] == 1
+ end
+ end
+
+ describe "follow requests counter" do
+ test "shows zero when no follow requests are pending" do
+ user = insert(:user)
+
+ assert %{follow_requests_count: 0} =
+ AccountView.render("show.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{follow_requests_count: 0} =
+ AccountView.render("show.json", %{user: user, for: user})
+ end
+
+ test "shows non-zero when follow requests are pending" do
+ user = insert(:user, locked: true)
+
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 1} =
+ AccountView.render("show.json", %{user: user, for: user})
+ end
+
+ test "decreases when accepting a follow request" do
+ user = insert(:user, locked: true)
+
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 1} =
+ AccountView.render("show.json", %{user: user, for: user})
+
+ {:ok, _other_user} = CommonAPI.accept_follow_request(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 0} =
+ AccountView.render("show.json", %{user: user, for: user})
+ end
+
+ test "decreases when rejecting a follow request" do
+ user = insert(:user, locked: true)
+
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 1} =
+ AccountView.render("show.json", %{user: user, for: user})
+
+ {:ok, _other_user} = CommonAPI.reject_follow_request(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 0} =
+ AccountView.render("show.json", %{user: user, for: user})
+ end
+
+ test "shows non-zero when historical unapproved requests are present" do
+ user = insert(:user, locked: true)
+
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ {:ok, user} = User.update_and_set_cache(user, %{locked: false})
+
+ assert %{locked: false, follow_requests_count: 1} =
+ AccountView.render("show.json", %{user: user, for: user})