2019-10-09 08:11:57 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 23:44:49 +01:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-10-09 08:11:57 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Mix.Tasks.Pleroma.CountStatusesTest do
|
2020-12-21 12:21:40 +01:00
|
|
|
# Uses log capture, has to stay synchronous
|
2019-10-09 08:11:57 +02:00
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
import ExUnit.CaptureIO, only: [capture_io: 1]
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "counts statuses" do
|
|
|
|
user = insert(:user)
|
2020-05-12 21:59:26 +02:00
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
|
|
|
{:ok, _} = CommonAPI.post(user, %{status: "test2"})
|
2019-10-09 08:11:57 +02:00
|
|
|
|
|
|
|
user2 = insert(:user)
|
2020-05-12 21:59:26 +02:00
|
|
|
{:ok, _} = CommonAPI.post(user2, %{status: "test3"})
|
2019-10-09 08:11:57 +02:00
|
|
|
|
|
|
|
user = refresh_record(user)
|
|
|
|
user2 = refresh_record(user2)
|
|
|
|
|
2019-10-16 20:59:21 +02:00
|
|
|
assert %{note_count: 2} = user
|
|
|
|
assert %{note_count: 1} = user2
|
2019-10-09 08:11:57 +02:00
|
|
|
|
2019-10-16 20:59:21 +02:00
|
|
|
{:ok, user} = User.update_note_count(user, 0)
|
|
|
|
{:ok, user2} = User.update_note_count(user2, 0)
|
2019-10-09 08:11:57 +02:00
|
|
|
|
2019-10-16 20:59:21 +02:00
|
|
|
assert %{note_count: 0} = user
|
|
|
|
assert %{note_count: 0} = user2
|
2019-10-09 08:11:57 +02:00
|
|
|
|
|
|
|
assert capture_io(fn -> Mix.Tasks.Pleroma.CountStatuses.run([]) end) == "Done\n"
|
|
|
|
|
2019-10-16 20:59:21 +02:00
|
|
|
assert %{note_count: 2} = refresh_record(user)
|
|
|
|
assert %{note_count: 1} = refresh_record(user2)
|
2019-10-09 08:11:57 +02:00
|
|
|
end
|
|
|
|
end
|