Fix/1019 correct count remote users
[akkoma] / test / user / synchronization_worker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.User.SynchronizationWorkerTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8
9 setup do
10 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
11
12 config = Pleroma.Config.get([:instance, :external_user_synchronization])
13
14 for_update = [enabled: true, interval: 1000]
15
16 Pleroma.Config.put([:instance, :external_user_synchronization], for_update)
17
18 on_exit(fn ->
19 Pleroma.Config.put([:instance, :external_user_synchronization], config)
20 end)
21
22 :ok
23 end
24
25 test "sync follow counters" do
26 user1 =
27 insert(:user,
28 local: false,
29 ap_id: "http://localhost:4001/users/masto_closed"
30 )
31
32 user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
33
34 {:ok, _} = Pleroma.User.SynchronizationWorker.start_link()
35 :timer.sleep(1500)
36
37 %{follower_count: followers, following_count: following} =
38 Pleroma.User.get_cached_user_info(user1)
39
40 assert followers == 437
41 assert following == 152
42
43 %{follower_count: followers, following_count: following} =
44 Pleroma.User.get_cached_user_info(user2)
45
46 assert followers == 527
47 assert following == 267
48 end
49 end