PublisherTest: Mock -> Mox
This commit is contained in:
parent
3de250da23
commit
b023e1591c
7 changed files with 62 additions and 51 deletions
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
import Mock
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
|
|
@ -170,10 +169,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
end
|
||||
|
||||
describe "publish/2" do
|
||||
test_with_mock "doesn't publish a non-public activity to quarantined instances.",
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "doesn't publish a non-public activity to quarantined instances." do
|
||||
Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}])
|
||||
|
||||
follower =
|
||||
|
|
@ -208,10 +204,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
)
|
||||
end
|
||||
|
||||
test_with_mock "Publishes a non-public activity to non-quarantined instances.",
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "Publishes a non-public activity to non-quarantined instances." do
|
||||
Config.put([:instance, :quarantined_instances], [{"somedomain.com", "some reason"}])
|
||||
|
||||
follower =
|
||||
|
|
@ -247,10 +240,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
)
|
||||
end
|
||||
|
||||
test_with_mock "Publishes to directly addressed actors with higher priority.",
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "Publishes to directly addressed actors with higher priority." do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
|
||||
actor = Pleroma.User.get_by_ap_id(note_activity.data["actor"])
|
||||
|
|
@ -259,21 +249,17 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Publisher.enqueue_one(
|
||||
%{
|
||||
inbox: :_,
|
||||
activity_id: note_activity.id
|
||||
},
|
||||
priority: 0
|
||||
)
|
||||
)
|
||||
assert_enqueued(
|
||||
worker: "Pleroma.Workers.PublisherWorker",
|
||||
args: %{
|
||||
"op" => "publish_one",
|
||||
"params" => %{"activity_id" => note_activity.id}
|
||||
},
|
||||
priority: 0
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "Publishes with the new actor if prepare_outgoing changes the actor.",
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "Publishes with the new actor if prepare_outgoing changes the actor." do
|
||||
mock(fn
|
||||
%{method: :post, url: "https://domain.com/users/nick1/inbox", body: body} ->
|
||||
{:ok, %Tesla.Env{status: 200, body: body}}
|
||||
|
|
@ -294,28 +280,27 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
data_attrs: %{"to" => [other_user.ap_id]}
|
||||
)
|
||||
|
||||
with_mock Pleroma.Web.ActivityPub.Transmogrifier,
|
||||
prepare_outgoing: fn data -> {:ok, Map.put(data, "actor", replaced_actor.ap_id)} end do
|
||||
prepared =
|
||||
Publisher.prepare_one(%{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
activity_id: note_activity.id,
|
||||
cc: ["https://domain.com/users/nick2/inbox"]
|
||||
})
|
||||
Pleroma.Web.ActivityPub.TransmogrifierMock
|
||||
|> Mox.expect(:prepare_outgoing, fn data ->
|
||||
{:ok, Map.put(data, "actor", replaced_actor.ap_id)}
|
||||
end)
|
||||
|
||||
{:ok, decoded} = Jason.decode(prepared.json)
|
||||
assert decoded["actor"] == replaced_actor.ap_id
|
||||
prepared =
|
||||
Publisher.prepare_one(%{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
activity_id: note_activity.id,
|
||||
cc: ["https://domain.com/users/nick2/inbox"]
|
||||
})
|
||||
|
||||
{:ok, published} = Publisher.publish_one(prepared)
|
||||
sent_activity = Jason.decode!(published.body)
|
||||
assert sent_activity["actor"] == replaced_actor.ap_id
|
||||
end
|
||||
{:ok, decoded} = Jason.decode(prepared.json)
|
||||
assert decoded["actor"] == replaced_actor.ap_id
|
||||
|
||||
{:ok, published} = Publisher.publish_one(prepared)
|
||||
sent_activity = Jason.decode!(published.body)
|
||||
assert sent_activity["actor"] == replaced_actor.ap_id
|
||||
end
|
||||
|
||||
test_with_mock "publishes an activity with BCC to all relevant peers.",
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "publishes an activity with BCC to all relevant peers." do
|
||||
follower =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
|
|
@ -347,10 +332,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
)
|
||||
end
|
||||
|
||||
test_with_mock "publishes a delete activity to peers who signed fetch requests to the create acitvity/object.",
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "publishes a delete activity to peers who signed fetch requests to the create acitvity/object." do
|
||||
fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
|
|
|
|||
|
|
@ -120,6 +120,11 @@ defmodule Pleroma.DataCase do
|
|||
|
||||
Mox.stub_with(Pleroma.DateTimeMock, Pleroma.DateTime.Impl)
|
||||
Mox.stub_with(Pleroma.SignatureMock, Pleroma.Signature)
|
||||
|
||||
Mox.stub_with(
|
||||
Pleroma.Web.ActivityPub.TransmogrifierMock,
|
||||
Pleroma.Web.ActivityPub.Transmogrifier
|
||||
)
|
||||
end
|
||||
|
||||
def ensure_local_uploader(context) do
|
||||
|
|
|
|||
|
|
@ -42,3 +42,7 @@ Mox.defmock(Pleroma.DateTimeMock, for: Pleroma.DateTime)
|
|||
Mox.defmock(Pleroma.MogrifyMock, for: Pleroma.MogrifyBehaviour)
|
||||
|
||||
Mox.defmock(Pleroma.SignatureMock, for: Pleroma.Signature.API)
|
||||
|
||||
Mox.defmock(Pleroma.Web.ActivityPub.TransmogrifierMock,
|
||||
for: Pleroma.Web.ActivityPub.Transmogrifier.API
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue