Add a task to re-count statuses for all users
[akkoma] / test / tasks / count_statuses_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.CountStatusesTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.User
9 alias Pleroma.Web.CommonAPI
10
11 import ExUnit.CaptureIO, only: [capture_io: 1]
12 import Pleroma.Factory
13
14 test "counts statuses" do
15 user = insert(:user)
16 {:ok, _} = CommonAPI.post(user, %{"status" => "test"})
17 {:ok, _} = CommonAPI.post(user, %{"status" => "test2"})
18
19 user2 = insert(:user)
20 {:ok, _} = CommonAPI.post(user2, %{"status" => "test3"})
21
22 user = refresh_record(user)
23 user2 = refresh_record(user2)
24
25 assert %{info: %{note_count: 2}} = user
26 assert %{info: %{note_count: 1}} = user2
27
28 {:ok, user} = User.update_info(user, &User.Info.set_note_count(&1, 0))
29 {:ok, user2} = User.update_info(user2, &User.Info.set_note_count(&1, 0))
30
31 assert %{info: %{note_count: 0}} = user
32 assert %{info: %{note_count: 0}} = user2
33
34 assert capture_io(fn -> Mix.Tasks.Pleroma.CountStatuses.run([]) end) == "Done\n"
35
36 assert %{info: %{note_count: 2}} = refresh_record(user)
37 assert %{info: %{note_count: 1}} = refresh_record(user2)
38 end
39 end