stat_test.exs (2344B)
1 # Pleroma: A lightweight social networking server 2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> 3 # SPDX-License-Identifier: AGPL-3.0-only 4 5 defmodule Pleroma.StateTest do 6 use Pleroma.DataCase 7 import Pleroma.Factory 8 alias Pleroma.Web.CommonAPI 9 10 describe "status visibility count" do 11 test "on new status" do 12 user = insert(:user) 13 other_user = insert(:user) 14 15 CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"}) 16 17 Enum.each(0..1, fn _ -> 18 CommonAPI.post(user, %{ 19 "visibility" => "unlisted", 20 "status" => "hey" 21 }) 22 end) 23 24 Enum.each(0..2, fn _ -> 25 CommonAPI.post(user, %{ 26 "visibility" => "direct", 27 "status" => "hey @#{other_user.nickname}" 28 }) 29 end) 30 31 Enum.each(0..3, fn _ -> 32 CommonAPI.post(user, %{ 33 "visibility" => "private", 34 "status" => "hey" 35 }) 36 end) 37 38 assert %{direct: 3, private: 4, public: 1, unlisted: 2} = 39 Pleroma.Stats.get_status_visibility_count() 40 end 41 42 test "on status delete" do 43 user = insert(:user) 44 {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"}) 45 assert %{public: 1} = Pleroma.Stats.get_status_visibility_count() 46 CommonAPI.delete(activity.id, user) 47 assert %{public: 0} = Pleroma.Stats.get_status_visibility_count() 48 end 49 50 test "on status visibility update" do 51 user = insert(:user) 52 {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"}) 53 assert %{public: 1, private: 0} = Pleroma.Stats.get_status_visibility_count() 54 {:ok, _} = CommonAPI.update_activity_scope(activity.id, %{"visibility" => "private"}) 55 assert %{public: 0, private: 1} = Pleroma.Stats.get_status_visibility_count() 56 end 57 58 test "doesn't count unrelated activities" do 59 user = insert(:user) 60 other_user = insert(:user) 61 {:ok, activity} = CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"}) 62 _ = CommonAPI.follow(user, other_user) 63 CommonAPI.favorite(other_user, activity.id) 64 CommonAPI.repeat(activity.id, other_user) 65 66 assert %{direct: 0, private: 0, public: 1, unlisted: 0} = 67 Pleroma.Stats.get_status_visibility_count() 68 end 69 end 70 end