diff options
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/activity_pub/pipeline_test.exs | 45 | ||||
| -rw-r--r-- | test/web/activity_pub/side_effects_test.exs | 8 | ||||
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 25 | 
3 files changed, 70 insertions, 8 deletions
| diff --git a/test/web/activity_pub/pipeline_test.exs b/test/web/activity_pub/pipeline_test.exs index 8deb64501..f2a231eaf 100644 --- a/test/web/activity_pub/pipeline_test.exs +++ b/test/web/activity_pub/pipeline_test.exs @@ -14,6 +14,51 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do        :ok      end +    test "when given an `object_data` in meta, Federation will receive a the original activity with the `object` field set to this embedded object" do +      activity = insert(:note_activity) +      object = %{"id" => "1", "type" => "Love"} +      meta = [local: true, object_data: object] + +      activity_with_object = %{activity | data: Map.put(activity.data, "object", object)} + +      with_mocks([ +        {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]}, +        { +          Pleroma.Web.ActivityPub.MRF, +          [], +          [filter: fn o -> {:ok, o} end] +        }, +        { +          Pleroma.Web.ActivityPub.ActivityPub, +          [], +          [persist: fn o, m -> {:ok, o, m} end] +        }, +        { +          Pleroma.Web.ActivityPub.SideEffects, +          [], +          [ +            handle: fn o, m -> {:ok, o, m} end, +            handle_after_transaction: fn m -> m end +          ] +        }, +        { +          Pleroma.Web.Federator, +          [], +          [publish: fn _o -> :ok end] +        } +      ]) do +        assert {:ok, ^activity, ^meta} = +                 Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) + +        assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) +        assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity)) +        assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta)) +        assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta)) +        refute called(Pleroma.Web.Federator.publish(activity)) +        assert_called(Pleroma.Web.Federator.publish(activity_with_object)) +      end +    end +      test "it goes through validation, filtering, persisting, side effects and federation for local activities" do        activity = insert(:note_activity)        meta = [local: true] diff --git a/test/web/activity_pub/side_effects_test.exs b/test/web/activity_pub/side_effects_test.exs index 2649b060a..4a08eb7ee 100644 --- a/test/web/activity_pub/side_effects_test.exs +++ b/test/web/activity_pub/side_effects_test.exs @@ -312,8 +312,12 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do        }      end -    test "deletes the original block", %{block_undo: block_undo, block: block} do -      {:ok, _block_undo, _} = SideEffects.handle(block_undo) +    test "deletes the original block", %{ +      block_undo: block_undo, +      block: block +    } do +      {:ok, _block_undo, _meta} = SideEffects.handle(block_undo) +        refute Activity.get_by_id(block.id)      end diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 7e11fede3..313dda21b 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -624,14 +624,27 @@ defmodule Pleroma.Web.CommonAPITest do        user = insert(:user)        other_user = insert(:user) -      {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"}) -      {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍") +      clear_config([:instance, :federating], true) + +      with_mock Pleroma.Web.Federator, +        publish: fn _ -> nil end do +        {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"}) +        {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍") + +        {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍") -      {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍") +        assert unreaction.data["type"] == "Undo" +        assert unreaction.data["object"] == reaction.data["id"] +        assert unreaction.local -      assert unreaction.data["type"] == "Undo" -      assert unreaction.data["object"] == reaction.data["id"] -      assert unreaction.local +        # On federation, it contains the undone (and deleted) object +        unreaction_with_object = %{ +          unreaction +          | data: Map.put(unreaction.data, "object", reaction.data) +        } + +        assert called(Pleroma.Web.Federator.publish(unreaction_with_object)) +      end      end      test "repeating a status" do | 
