diff options
Diffstat (limited to 'test/web')
3 files changed, 67 insertions, 4 deletions
| diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index fb7fd9e79..2b4a04afd 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -105,10 +105,20 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do        other_user = insert(:user)        {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)        assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) -      info = Map.put(user.info, :hide_followers, true) +      info = Map.merge(user.info, %{hide_followers_count: true, hide_followers: true})        user = Map.put(user, :info, info)        assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})      end + +    test "sets correct totalItems when followers are hidden but the follower counter is not" do +      user = insert(:user) +      other_user = insert(:user) +      {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) +      assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) +      info = Map.merge(user.info, %{hide_followers_count: false, hide_followers: true}) +      user = Map.put(user, :info, info) +      assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) +    end    end    describe "following" do @@ -117,9 +127,19 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do        other_user = insert(:user)        {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)        assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) -      info = Map.put(user.info, :hide_follows, true) +      info = Map.merge(user.info, %{hide_follows_count: true, hide_follows: true})        user = Map.put(user, :info, info)        assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})      end + +    test "sets correct totalItems when follows are hidden but the follow counter is not" do +      user = insert(:user) +      other_user = insert(:user) +      {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user) +      assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) +      info = Map.merge(user.info, %{hide_follows_count: false, hide_follows: true}) +      user = Map.put(user, :info, info) +      assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) +    end    end  end diff --git a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs index 87ee82050..89d4ca37e 100644 --- a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs +++ b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs @@ -128,6 +128,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do        assert user["pleroma"]["hide_followers"] == true      end +    test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do +      user = insert(:user) + +      conn = +        conn +        |> assign(:user, user) +        |> patch("/api/v1/accounts/update_credentials", %{ +          hide_followers_count: "true", +          hide_follows_count: "true" +        }) + +      assert user = json_response(conn, 200) +      assert user["pleroma"]["hide_followers_count"] == true +      assert user["pleroma"]["hide_follows_count"] == true +    end +      test "updates the user's skip_thread_containment option", %{conn: conn} do        user = insert(:user) diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 1d8b28339..8ff6751d3 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -79,6 +79,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          hide_favorites: true,          hide_followers: false,          hide_follows: false, +        hide_followers_count: false, +        hide_follows_count: false,          relationship: %{},          skip_thread_containment: false        } @@ -147,6 +149,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          hide_favorites: true,          hide_followers: false,          hide_follows: false, +        hide_followers_count: false, +        hide_follows_count: false,          relationship: %{},          skip_thread_containment: false        } @@ -318,6 +322,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          hide_favorites: true,          hide_followers: false,          hide_follows: false, +        hide_followers_count: false, +        hide_follows_count: false,          relationship: %{            id: to_string(user.id),            following: false, @@ -361,8 +367,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do    end    describe "hiding follows/following" do -    test "shows when follows/following are hidden and sets follower/following count to 0" do -      user = insert(:user, info: %{hide_followers: true, hide_follows: true}) +    test "shows when follows/followers stats are hidden and sets follow/follower count to 0" do +      info = %{ +        hide_followers: true, +        hide_followers_count: true, +        hide_follows: true, +        hide_follows_count: true +      } + +      user = insert(:user, info: info) +        other_user = insert(:user)        {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)        {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) @@ -370,6 +384,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        assert %{                 followers_count: 0,                 following_count: 0, +               pleroma: %{hide_follows_count: true, hide_followers_count: true} +             } = AccountView.render("account.json", %{user: user}) +    end + +    test "shows when follows/followers are hidden" do +      user = insert(:user, info: %{hide_followers: true, hide_follows: true}) +      other_user = insert(:user) +      {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) +      {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) + +      assert %{ +               followers_count: 1, +               following_count: 1,                 pleroma: %{hide_follows: true, hide_followers: true}               } = AccountView.render("account.json", %{user: user})      end | 
