1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.CountStatusesTest do
6 # Uses log capture, has to stay synchronous
10 alias Pleroma.Web.CommonAPI
12 import ExUnit.CaptureIO, only: [capture_io: 1]
13 import Pleroma.Factory
15 test "counts statuses" do
17 {:ok, _} = CommonAPI.post(user, %{status: "test"})
18 {:ok, _} = CommonAPI.post(user, %{status: "test2"})
21 {:ok, _} = CommonAPI.post(user2, %{status: "test3"})
23 user = refresh_record(user)
24 user2 = refresh_record(user2)
26 assert %{note_count: 2} = user
27 assert %{note_count: 1} = user2
29 {:ok, user} = User.update_note_count(user, 0)
30 {:ok, user2} = User.update_note_count(user2, 0)
32 assert %{note_count: 0} = user
33 assert %{note_count: 0} = user2
35 assert capture_io(fn -> Mix.Tasks.Pleroma.CountStatuses.run([]) end) == "Done\n"
37 assert %{note_count: 2} = refresh_record(user)
38 assert %{note_count: 1} = refresh_record(user2)