1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.StatsTest do
8 alias Pleroma.Web.CommonAPI
10 describe "user count" do
11 test "it ignores internal users" do
12 _user = insert(:user, local: true)
13 _internal = insert(:user, local: true, nickname: nil)
14 _internal = Pleroma.Web.ActivityPub.Relay.get_actor()
16 assert match?(%{stats: %{user_count: 1}}, Pleroma.Stats.calculate_stat_data())
20 describe "status visibility count" do
21 test "on new status" do
23 other_user = insert(:user)
25 CommonAPI.post(user, %{visibility: "public", status: "hey"})
27 Enum.each(0..1, fn _ ->
28 CommonAPI.post(user, %{
29 visibility: "unlisted",
34 Enum.each(0..2, fn _ ->
35 CommonAPI.post(user, %{
37 status: "hey @#{other_user.nickname}"
41 Enum.each(0..3, fn _ ->
42 CommonAPI.post(user, %{
43 visibility: "private",
48 assert %{direct: 3, private: 4, public: 1, unlisted: 2} =
49 Pleroma.Stats.get_status_visibility_count()
52 test "on status delete" do
54 {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
55 assert %{public: 1} = Pleroma.Stats.get_status_visibility_count()
56 CommonAPI.delete(activity.id, user)
57 assert %{public: 0} = Pleroma.Stats.get_status_visibility_count()
60 test "on status visibility update" do
62 {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
63 assert %{public: 1, private: 0} = Pleroma.Stats.get_status_visibility_count()
64 {:ok, _} = CommonAPI.update_activity_scope(activity.id, %{visibility: "private"})
65 assert %{public: 0, private: 1} = Pleroma.Stats.get_status_visibility_count()
68 test "doesn't count unrelated activities" do
70 other_user = insert(:user)
71 {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
72 _ = CommonAPI.follow(user, other_user)
73 CommonAPI.favorite(other_user, activity.id)
74 CommonAPI.repeat(activity.id, other_user)
76 assert %{direct: 0, private: 0, public: 1, unlisted: 0} =
77 Pleroma.Stats.get_status_visibility_count()