diff options
author | kaniini <ariadne@dereferenced.org> | 2019-07-11 13:01:11 +0000 |
---|---|---|
committer | kaniini <ariadne@dereferenced.org> | 2019-07-11 13:01:11 +0000 |
commit | e4e3fd7e5552db274655d58bbbec1e4faabf7ccd (patch) | |
tree | 744524f1eac36a5c6d3b0cfb0aa121e920c86dbc /test | |
parent | 6c491b2006ef2f279e6ffbb4ac007b7740c6d50d (diff) | |
parent | 59e16fc45a2fe1fa6bfeaecaa35f485b8a34bb6d (diff) | |
download | pleroma-e4e3fd7e5552db274655d58bbbec1e4faabf7ccd.tar.gz |
Merge branch 'fix/1019-refactor' into 'develop'
Fix/1019 refactor
See merge request pleroma/pleroma!1397
Diffstat (limited to 'test')
-rw-r--r-- | test/support/factory.ex | 1 | ||||
-rw-r--r-- | test/tasks/robots_txt_test.exs | 2 | ||||
-rw-r--r-- | test/user/synchronization_test.exs | 104 | ||||
-rw-r--r-- | test/user/synchronization_worker_test.exs | 49 | ||||
-rw-r--r-- | test/user_test.exs | 54 | ||||
-rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 29 |
6 files changed, 39 insertions, 200 deletions
diff --git a/test/support/factory.ex b/test/support/factory.ex index a9f750eec..531eb81e4 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -38,6 +38,7 @@ defmodule Pleroma.Factory do user | ap_id: User.ap_id(user), follower_address: User.ap_followers(user), + following_address: User.ap_following(user), following: [User.ap_id(user)] } end diff --git a/test/tasks/robots_txt_test.exs b/test/tasks/robots_txt_test.exs index 97147a919..78a3f17b4 100644 --- a/test/tasks/robots_txt_test.exs +++ b/test/tasks/robots_txt_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.RobotsTxtTest do - use ExUnit.Case, async: true + use ExUnit.Case alias Mix.Tasks.Pleroma.RobotsTxt test "creates new dir" do diff --git a/test/user/synchronization_test.exs b/test/user/synchronization_test.exs deleted file mode 100644 index 67b669431..000000000 --- a/test/user/synchronization_test.exs +++ /dev/null @@ -1,104 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.User.SynchronizationTest do - use Pleroma.DataCase - import Pleroma.Factory - alias Pleroma.User - alias Pleroma.User.Synchronization - - setup do - Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end) - :ok - end - - test "update following/followers 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") - - users = User.external_users() - assert length(users) == 2 - {user, %{}} = Synchronization.call(users, %{}) - assert user == List.last(users) - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) - assert followers == 437 - assert following == 152 - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) - - assert followers == 527 - assert following == 267 - end - - test "don't check host if errors exist" do - user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1") - - user2 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser2") - - users = User.external_users() - assert length(users) == 2 - - {user, %{"domain-with-errors" => 2}} = - Synchronization.call(users, %{"domain-with-errors" => 2}, max_retries: 2) - - assert user == List.last(users) - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) - assert followers == 0 - assert following == 0 - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) - - assert followers == 0 - assert following == 0 - end - - test "don't check host if errors appeared" do - user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1") - - user2 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser2") - - users = User.external_users() - assert length(users) == 2 - - {user, %{"domain-with-errors" => 2}} = Synchronization.call(users, %{}, max_retries: 2) - - assert user == List.last(users) - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) - assert followers == 0 - assert following == 0 - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) - - assert followers == 0 - assert following == 0 - end - - test "other users after error appeared" do - user1 = insert(:user, local: false, ap_id: "http://domain-with-errors:4001/users/fuser1") - user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2") - - users = User.external_users() - assert length(users) == 2 - - {user, %{"domain-with-errors" => 2}} = Synchronization.call(users, %{}, max_retries: 2) - assert user == List.last(users) - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) - assert followers == 0 - assert following == 0 - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) - - assert followers == 527 - assert following == 267 - end -end diff --git a/test/user/synchronization_worker_test.exs b/test/user/synchronization_worker_test.exs deleted file mode 100644 index 835c5327f..000000000 --- a/test/user/synchronization_worker_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -# 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 diff --git a/test/user_test.exs b/test/user_test.exs index 62be79b4f..7c3fe976d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -54,6 +54,14 @@ defmodule Pleroma.UserTest do assert expected_followers_collection == User.ap_followers(user) end + test "ap_following returns the following collection for the user" do + user = UserBuilder.build() + + expected_followers_collection = "#{User.ap_id(user)}/following" + + assert expected_followers_collection == User.ap_following(user) + end + test "returns all pending follow requests" do unlocked = insert(:user) locked = insert(:user, %{info: %{locked: true}}) @@ -1240,52 +1248,6 @@ defmodule Pleroma.UserTest do assert User.external_users(max_id: fdb_user2.id, limit: 1) == [] end - - test "sync_follow_counters/1", %{user1: user1, user2: user2} do - {:ok, _pid} = Agent.start_link(fn -> %{} end, name: :domain_errors) - - :ok = User.sync_follow_counters() - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) - assert followers == 437 - assert following == 152 - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) - - assert followers == 527 - assert following == 267 - - Agent.stop(:domain_errors) - end - - test "sync_follow_counters/1 in separate batches", %{user1: user1, user2: user2} do - {:ok, _pid} = Agent.start_link(fn -> %{} end, name: :domain_errors) - - :ok = User.sync_follow_counters(limit: 1) - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) - assert followers == 437 - assert following == 152 - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) - - assert followers == 527 - assert following == 267 - - Agent.stop(:domain_errors) - end - - test "perform/1 with :sync_follow_counters", %{user1: user1, user2: user2} do - :ok = User.perform(:sync_follow_counters) - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) - assert followers == 437 - assert following == 152 - - %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) - - assert followers == 527 - assert following == 267 - end end describe "set_info_cache/2" do diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 825e99879..b896a532b 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1121,6 +1121,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert user.info.ap_enabled assert user.info.note_count == 1 assert user.follower_address == "https://niu.moe/users/rye/followers" + assert user.following_address == "https://niu.moe/users/rye/following" user = User.get_cached_by_id(user.id) assert user.info.note_count == 1 @@ -1358,4 +1359,32 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do refute recipient.follower_address in fixed_object["to"] end end + + test "update_following_followers_counters/1" do + user1 = + insert(:user, + local: false, + follower_address: "http://localhost:4001/users/masto_closed/followers", + following_address: "http://localhost:4001/users/masto_closed/following" + ) + + user2 = + insert(:user, + local: false, + follower_address: "http://localhost:4001/users/fuser2/followers", + following_address: "http://localhost:4001/users/fuser2/following" + ) + + Transmogrifier.update_following_followers_counters(user1) + Transmogrifier.update_following_followers_counters(user2) + + %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1) + assert followers == 437 + assert following == 152 + + %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2) + + assert followers == 527 + assert following == 267 + end end |