Merge develop
authorRoman Chvanikov <chvanikoff@pm.me>
Wed, 13 May 2020 16:56:40 +0000 (19:56 +0300)
committerRoman Chvanikov <chvanikoff@pm.me>
Wed, 13 May 2020 16:56:40 +0000 (19:56 +0300)
1  2 
CHANGELOG.md
lib/pleroma/web/admin_api/admin_api_controller.ex
test/stats_test.exs
test/tasks/refresh_counter_cache_test.exs
test/web/admin_api/admin_api_controller_test.exs

diff --cc CHANGELOG.md
Simple merge
index 33ed0b7dd12ab4492b75bf7132bf76e5dd8d69b4,4b76e2e782b12de65e9d9f94e343b58e28fc7239..f09d8d31a689f69fc52a211cc538695fbc599ede
@@@ -17,13 -17,12 +17,13 @@@ defmodule Pleroma.StatsTest d
      end
    end
  
 -  describe "status visibility count" do
 +  describe "status visibility sum count" do
      test "on new status" do
 +      instance2 = "instance2.tld"
        user = insert(:user)
 -      other_user = insert(:user)
 +      other_user = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
  
-       CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+       CommonAPI.post(user, %{visibility: "public", status: "hey"})
  
        Enum.each(0..1, fn _ ->
          CommonAPI.post(user, %{
  
      test "on status delete" do
        user = insert(:user)
-       {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+       {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
 -      assert %{public: 1} = Pleroma.Stats.get_status_visibility_count()
 +      assert %{"public" => 1} = Pleroma.Stats.get_status_visibility_count()
        CommonAPI.delete(activity.id, user)
 -      assert %{public: 0} = Pleroma.Stats.get_status_visibility_count()
 +      assert %{"public" => 0} = Pleroma.Stats.get_status_visibility_count()
      end
  
      test "on status visibility update" do
        user = insert(:user)
-       {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+       {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
 -      assert %{public: 1, private: 0} = Pleroma.Stats.get_status_visibility_count()
 +      assert %{"public" => 1, "private" => 0} = Pleroma.Stats.get_status_visibility_count()
-       {:ok, _} = CommonAPI.update_activity_scope(activity.id, %{"visibility" => "private"})
+       {:ok, _} = CommonAPI.update_activity_scope(activity.id, %{visibility: "private"})
 -      assert %{public: 0, private: 1} = Pleroma.Stats.get_status_visibility_count()
 +      assert %{"public" => 0, "private" => 1} = Pleroma.Stats.get_status_visibility_count()
      end
  
      test "doesn't count unrelated activities" do
                 Pleroma.Stats.get_status_visibility_count()
      end
    end
-       CommonAPI.post(user1, %{"visibility" => "public", "status" => "hey"})
 +
 +  describe "status visibility by instance count" do
 +    test "single instance" do
 +      local_instance = Pleroma.Web.Endpoint.url() |> String.split("//") |> Enum.at(1)
 +      instance2 = "instance2.tld"
 +      user1 = insert(:user)
 +      user2 = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
 +
-           "visibility" => "unlisted",
-           "status" => "hey"
++      CommonAPI.post(user1, %{visibility: "public", status: "hey"})
 +
 +      Enum.each(1..5, fn _ ->
 +        CommonAPI.post(user1, %{
-           "visibility" => "direct",
-           "status" => "hey @#{user2.nickname}"
++          visibility: "unlisted",
++          status: "hey"
 +        })
 +      end)
 +
 +      Enum.each(1..10, fn _ ->
 +        CommonAPI.post(user1, %{
-           "visibility" => "private",
-           "status" => "hey"
++          visibility: "direct",
++          status: "hey @#{user2.nickname}"
 +        })
 +      end)
 +
 +      Enum.each(1..20, fn _ ->
 +        CommonAPI.post(user2, %{
++          visibility: "private",
++          status: "hey"
 +        })
 +      end)
 +
 +      assert %{"direct" => 10, "private" => 0, "public" => 1, "unlisted" => 5} =
 +               Pleroma.Stats.get_status_visibility_count(local_instance)
 +
 +      assert %{"direct" => 0, "private" => 20, "public" => 0, "unlisted" => 0} =
 +               Pleroma.Stats.get_status_visibility_count(instance2)
 +    end
 +  end
  end
index c3de89ac0d0d0f33fcafb4b2be5dd27cc8853d4a,e4b0dd627347ae52e8b3ef00ebeff706b387d6b3..dd0c6b88d19a70e3d8179ef67a0cb0cde79c4b5e
@@@ -3612,26 -3603,6 +3603,26 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI
        assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 2} =
                 response["status_visibility"]
      end
-       CommonAPI.post(user1, %{"visibility" => "public", "status" => "hey"})
-       CommonAPI.post(user2, %{"visibility" => "unlisted", "status" => "hey"})
-       CommonAPI.post(user2, %{"visibility" => "private", "status" => "hey"})
 +
 +    test "by instance", %{conn: conn} do
 +      admin = insert(:user, is_admin: true)
 +      user1 = insert(:user)
 +      instance2 = "instance2.tld"
 +      user2 = insert(:user, %{ap_id: "https://#{instance2}/@actor"})
 +
++      CommonAPI.post(user1, %{visibility: "public", status: "hey"})
++      CommonAPI.post(user2, %{visibility: "unlisted", status: "hey"})
++      CommonAPI.post(user2, %{visibility: "private", status: "hey"})
 +
 +      response =
 +        conn
 +        |> assign(:user, admin)
 +        |> get("/api/pleroma/admin/stats", instance: instance2)
 +        |> json_response(200)
 +
 +      assert %{"direct" => 0, "private" => 1, "public" => 0, "unlisted" => 1} =
 +               response["status_visibility"]
 +    end
    end
  
    describe "POST /api/pleroma/admin/oauth_app" do