Replace user.following with Pleroma.FollowingRelationship

This commit is contained in:
Egor Kislitsyn 2019-10-11 02:35:32 +07:00
commit 059005ff82
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
28 changed files with 275 additions and 235 deletions

View file

@ -72,25 +72,25 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
describe "running update_users_following_followers_counts" do
test "following and followers count are updated" do
[user, user2] = insert_pair(:user)
{:ok, %User{following: following, info: info} = user} = User.follow(user, user2)
{:ok, %User{info: info} = user} = User.follow(user, user2)
following = User.following(user)
assert length(following) == 2
assert info.follower_count == 0
{:ok, user} =
user
|> Ecto.Changeset.change(%{following: following ++ following})
|> User.change_info(&Ecto.Changeset.change(&1, %{follower_count: 3}))
|> Repo.update()
assert length(user.following) == 4
assert user.info.follower_count == 3
assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"])
user = User.get_by_id(user.id)
assert length(user.following) == 2
assert length(User.following(user)) == 2
assert user.info.follower_count == 0
end
end

View file

@ -51,7 +51,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
target_user = User.get_cached_by_ap_id(target_instance)
follow_activity = Utils.fetch_latest_follow(local_user, target_user)
User.follow(local_user, target_user)
assert "#{target_instance}/followers" in refresh_record(local_user).following
assert "#{target_instance}/followers" in User.following(local_user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
@ -68,7 +68,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
assert undo_activity.data["type"] == "Undo"
assert undo_activity.data["actor"] == local_user.ap_id
assert undo_activity.data["object"] == cancelled_activity.data
refute "#{target_instance}/followers" in refresh_record(local_user).following
refute "#{target_instance}/followers" in User.following(local_user)
end
end
@ -78,20 +78,18 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
refute_receive {:mix_shell, :info, _}
Pleroma.Web.ActivityPub.Relay.get_actor()
|> Ecto.Changeset.change(
following: [
"http://test-app.com/user/test1",
"http://test-app.com/user/test1",
"http://test-app-42.com/user/test1"
]
)
|> Pleroma.User.update_and_set_cache()
relay_user = Relay.get_actor()
["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
|> Enum.each(fn ap_id ->
{:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
User.follow(relay_user, user)
end)
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
assert_receive {:mix_shell, :info, ["test-app.com"]}
assert_receive {:mix_shell, :info, ["test-app-42.com"]}
assert_receive {:mix_shell, :info, ["mstdn.io"]}
assert_receive {:mix_shell, :info, ["mastodon.example.org"]}
end
end
end

View file

@ -139,7 +139,8 @@ defmodule Mix.Tasks.Pleroma.UserTest do
describe "running unsubscribe" do
test "user is unsubscribed" do
followed = insert(:user)
user = insert(:user, %{following: [User.ap_followers(followed)]})
user = insert(:user)
User.follow(user, followed, "accept")
Mix.Tasks.Pleroma.User.run(["unsubscribe", user.nickname])
@ -154,7 +155,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ "Successfully unsubscribed"
user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(user.following)
assert Enum.empty?(User.get_friends(user))
assert user.info.deactivated
end