forked from AkkomaGang/akkoma
pipeline_test: Fix usage of %Activity{}
This commit is contained in:
parent
9015df2229
commit
5ae27c8451
3 changed files with 19 additions and 8 deletions
|
@ -169,7 +169,7 @@ def cast_and_apply(%{"type" => "Article"} = object) do
|
|||
|
||||
def cast_and_apply(o), do: {:error, {:validator_not_set, o}}
|
||||
|
||||
# is_struct/1 isn't present in Elixir 1.8.x
|
||||
# is_struct/1 appears in Elixir 1.11
|
||||
def stringify_keys(%{__struct__: _} = object) do
|
||||
object
|
||||
|> Map.from_struct()
|
||||
|
|
|
@ -40,6 +40,8 @@ def common_pipeline(object, meta) do
|
|||
end
|
||||
end
|
||||
|
||||
def do_common_pipeline(%{__struct__: _}, _meta), do: {:error, :is_struct}
|
||||
|
||||
def do_common_pipeline(object, meta) do
|
||||
with {_, {:ok, validated_object, meta}} <-
|
||||
{:validate_object, @object_validator.validate(object, meta)},
|
||||
|
|
|
@ -25,9 +25,6 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
MRFMock
|
||||
|> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
SideEffectsMock
|
||||
|> expect(:handle, fn o, m -> {:ok, o, m} end)
|
||||
|> expect(:handle_after_transaction, fn m -> m end)
|
||||
|
@ -42,6 +39,9 @@ test "when given an `object_data` in meta, Federation will receive a the origina
|
|||
|
||||
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity_with_object -> :ok end)
|
||||
|
||||
|
@ -50,7 +50,7 @@ test "when given an `object_data` in meta, Federation will receive a the origina
|
|||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
|
||||
activity,
|
||||
activity.data,
|
||||
meta
|
||||
)
|
||||
end
|
||||
|
@ -59,6 +59,9 @@ test "it goes through validation, filtering, persisting, side effects and federa
|
|||
activity = insert(:note_activity)
|
||||
meta = [local: true]
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity -> :ok end)
|
||||
|
||||
|
@ -66,29 +69,35 @@ test "it goes through validation, filtering, persisting, side effects and federa
|
|||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: false]
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: true]
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn _, m -> {:ok, activity, m} end)
|
||||
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> false end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity.data, meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue