summaryrefslogtreecommitdiff
path: root/test/user/synchronization_worker_test.exs
blob: 835c5327fb18a236398b500fe4cf39b62ec52b56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.User.SynchronizationWorkerTest do
  use Pleroma.DataCase
  import Pleroma.Factory

  setup do
    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)

    config = Pleroma.Config.get([:instance, :external_user_synchronization])

    for_update = [enabled: true, interval: 1000]

    Pleroma.Config.put([:instance, :external_user_synchronization], for_update)

    on_exit(fn ->
      Pleroma.Config.put([:instance, :external_user_synchronization], config)
    end)

    :ok
  end

  test "sync follow counters" do
    user1 =
      insert(:user,
        local: false,
        ap_id: "http://localhost:4001/users/masto_closed"
      )

    user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")

    {:ok, _} = Pleroma.User.SynchronizationWorker.start_link()
    :timer.sleep(1500)

    %{follower_count: followers, following_count: following} =
      Pleroma.User.get_cached_user_info(user1)

    assert followers == 437
    assert following == 152

    %{follower_count: followers, following_count: following} =
      Pleroma.User.get_cached_user_info(user2)

    assert followers == 527
    assert following == 267
  end
end