Utils: Split update_follow_state and update_follow_state_for_all.
This commit is contained in:
parent
827a51e777
commit
ad19bfc7fe
2 changed files with 50 additions and 2 deletions
|
@ -376,8 +376,8 @@ def remove_like_from_object(%Activity{data: %{"actor" => actor}}, object) do
|
|||
@doc """
|
||||
Updates a follow activity's state (for locked accounts).
|
||||
"""
|
||||
def update_follow_state(
|
||||
%Activity{data: %{"actor" => actor, "object" => object, "state" => "pending"}} = activity,
|
||||
def update_follow_state_for_all(
|
||||
%Activity{data: %{"actor" => actor, "object" => object}} = activity,
|
||||
state
|
||||
) do
|
||||
try do
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
use Pleroma.DataCase
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
|
@ -247,4 +248,51 @@ test "fetches only Create activities" do
|
|||
assert fetched_vote.id == vote.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_follow_state_for_all/2" do
|
||||
test "updates the state of all Follow activities with the same actor and object" do
|
||||
user = insert(:user, info: %{locked: true})
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, user)
|
||||
{:ok, follow_activity_two} = ActivityPub.follow(follower, user)
|
||||
|
||||
data =
|
||||
follow_activity_two.data
|
||||
|> Map.put("state", "accept")
|
||||
|
||||
cng = Ecto.Changeset.change(follow_activity_two, data: data)
|
||||
|
||||
{:ok, follow_activity_two} = Repo.update(cng)
|
||||
|
||||
{:ok, follow_activity_two} =
|
||||
Utils.update_follow_state_for_all(follow_activity_two, "accept")
|
||||
|
||||
assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
|
||||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_follow_state/2" do
|
||||
test "updates the state of the given follow activity" do
|
||||
user = insert(:user, info: %{locked: true})
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, user)
|
||||
{:ok, follow_activity_two} = ActivityPub.follow(follower, user)
|
||||
|
||||
data =
|
||||
follow_activity_two.data
|
||||
|> Map.put("state", "accept")
|
||||
|
||||
cng = Ecto.Changeset.change(follow_activity_two, data: data)
|
||||
|
||||
{:ok, follow_activity_two} = Repo.update(cng)
|
||||
|
||||
{:ok, follow_activity_two} = Utils.update_follow_state(follow_activity_two, "reject")
|
||||
|
||||
assert Repo.get(Activity, follow_activity.id).data["state"] == "pending"
|
||||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue