Update preparing and tests for current codebase
This commit is contained in:
parent
9d62fca315
commit
1df7d428bc
2 changed files with 24 additions and 29 deletions
|
|
@ -92,19 +92,16 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|
||||||
uri = %{path: path} = URI.parse(inbox)
|
uri = %{path: path} = URI.parse(inbox)
|
||||||
|
|
||||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
{actor, activity, data} =
|
|
||||||
|
{actor, data} =
|
||||||
with {_, false} <- {:actor_changed?, data["actor"] != activity.data["actor"]} do
|
with {_, false} <- {:actor_changed?, data["actor"] != activity.data["actor"]} do
|
||||||
{orig_actor, activity, data}
|
{actor, data}
|
||||||
else
|
else
|
||||||
{:actor_changed?, true} ->
|
{:actor_changed?, true} ->
|
||||||
# If prepare_outgoing changes the actor, re-get it from the db
|
# If prepare_outgoing changes the actor, re-get it from the db
|
||||||
actor = User.get_cached_by_ap_id(data["actor"])
|
new_actor = User.get_cached_by_ap_id(data["actor"])
|
||||||
|
{new_actor, data}
|
||||||
activity = %Activity{activity | actor: actor.ap_id}
|
end
|
||||||
|
|
||||||
{actor, activity, data}
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
param_cc = Map.get(params, :cc, [])
|
param_cc = Map.get(params, :cc, [])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -380,14 +380,18 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test_with_mock "Publishes with the new actor if prepare_outgoing changes the actor.",
|
test_with_mock "Publishes with the new actor if prepare_outgoing changes the actor.",
|
||||||
Pleroma.Web.Federator.Publisher,
|
Pleroma.Web.ActivityPub.Publisher,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
|
mock(fn
|
||||||
|
%{method: :post, url: "https://domain.com/users/nick1/inbox", body: body} ->
|
||||||
|
{:ok, %Tesla.Env{status: 200, body: body}}
|
||||||
|
end)
|
||||||
|
|
||||||
other_user =
|
other_user =
|
||||||
insert(:user, %{
|
insert(:user, %{
|
||||||
local: false,
|
local: false,
|
||||||
inbox: "https://domain.com/users/nick1/inbox",
|
inbox: "https://domain.com/users/nick1/inbox"
|
||||||
ap_enabled: true
|
|
||||||
})
|
})
|
||||||
|
|
||||||
actor = insert(:user)
|
actor = insert(:user)
|
||||||
|
|
@ -401,25 +405,19 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
|
|
||||||
with_mock Pleroma.Web.ActivityPub.Transmogrifier,
|
with_mock Pleroma.Web.ActivityPub.Transmogrifier,
|
||||||
prepare_outgoing: fn data -> {:ok, Map.put(data, "actor", replaced_actor.ap_id)} end do
|
prepare_outgoing: fn data -> {:ok, Map.put(data, "actor", replaced_actor.ap_id)} end do
|
||||||
res = Publisher.publish(actor, note_activity)
|
prepared =
|
||||||
|
Publisher.prepare_one(%{
|
||||||
|
inbox: "https://domain.com/users/nick1/inbox",
|
||||||
|
activity_id: note_activity.id,
|
||||||
|
cc: ["https://domain.com/users/nick2/inbox"]
|
||||||
|
})
|
||||||
|
|
||||||
assert res == :ok
|
{:ok, decoded} = Jason.decode(prepared.json)
|
||||||
|
assert decoded["actor"] == replaced_actor.ap_id
|
||||||
|
|
||||||
refute called(
|
{:ok, published} = Publisher.publish_one(prepared)
|
||||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
sent_activity = Jason.decode!(published.body)
|
||||||
inbox: "https://domain.com/users/nick1/inbox",
|
assert sent_activity["actor"] == replaced_actor.ap_id
|
||||||
actor_id: actor.id,
|
|
||||||
id: note_activity.data["id"]
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
assert called(
|
|
||||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
|
||||||
inbox: "https://domain.com/users/nick1/inbox",
|
|
||||||
actor_id: replaced_actor.id,
|
|
||||||
id: note_activity.data["id"]
|
|
||||||
})
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue