diff options
Diffstat (limited to 'test/web/activity_pub')
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 58 | ||||
| -rw-r--r-- | test/web/activity_pub/utils_test.exs | 57 | 
2 files changed, 115 insertions, 0 deletions
| diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 89e3dafd6..e5e3c8d33 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -162,6 +162,36 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["object"]["url"] == "https://prismo.news/posts/83"      end +    test "it cleans up incoming notices which are not really DMs" do +      user = insert(:user) +      other_user = insert(:user) + +      to = [user.ap_id, other_user.ap_id] + +      data = +        File.read!("test/fixtures/mastodon-post-activity.json") +        |> Poison.decode!() +        |> Map.put("to", to) +        |> Map.put("cc", []) + +      object = +        data["object"] +        |> Map.put("to", to) +        |> Map.put("cc", []) + +      data = Map.put(data, "object", object) + +      {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + +      assert data["to"] == [] +      assert data["cc"] == to + +      object = data["object"] + +      assert object["to"] == [] +      assert object["cc"] == to +    end +      test "it works for incoming follow requests" do        user = insert(:user) @@ -872,6 +902,34 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert modified["object"]["likes"]["type"] == "OrderedCollection"        assert modified["object"]["likes"]["totalItems"] == 0      end + +    test "the directMessage flag is present" do +      user = insert(:user) +      other_user = insert(:user) + +      {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu :moominmamma:"}) + +      {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) + +      assert modified["directMessage"] == false + +      {:ok, activity} = +        CommonAPI.post(user, %{"status" => "@#{other_user.nickname} :moominmamma:"}) + +      {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) + +      assert modified["directMessage"] == false + +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "status" => "@#{other_user.nickname} :moominmamma:", +          "visibility" => "direct" +        }) + +      {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) + +      assert modified["directMessage"] == true +    end    end    describe "user upgrade" do diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs new file mode 100644 index 000000000..aeed0564c --- /dev/null +++ b/test/web/activity_pub/utils_test.exs @@ -0,0 +1,57 @@ +defmodule Pleroma.Web.ActivityPub.UtilsTest do +  use Pleroma.DataCase +  alias Pleroma.Web.ActivityPub.Utils + +  describe "determine_explicit_mentions()" do +    test "works with an object that has mentions" do +      object = %{ +        "tag" => [ +          %{ +            "type" => "Mention", +            "href" => "https://example.com/~alyssa", +            "name" => "Alyssa P. Hacker" +          } +        ] +      } + +      assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"] +    end + +    test "works with an object that does not have mentions" do +      object = %{ +        "tag" => [ +          %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"} +        ] +      } + +      assert Utils.determine_explicit_mentions(object) == [] +    end + +    test "works with an object that has mentions and other tags" do +      object = %{ +        "tag" => [ +          %{ +            "type" => "Mention", +            "href" => "https://example.com/~alyssa", +            "name" => "Alyssa P. Hacker" +          }, +          %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"} +        ] +      } + +      assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"] +    end + +    test "works with an object that has no tags" do +      object = %{} + +      assert Utils.determine_explicit_mentions(object) == [] +    end + +    test "works with an object that has only IR tags" do +      object = %{"tag" => ["2hu"]} + +      assert Utils.determine_explicit_mentions(object) == [] +    end +  end +end | 
