Merge branch 'account-notes' into 'develop'
[akkoma] / test / pleroma / web / activity_pub / transmogrifier_test.exs
index 28d7e1e3c0d5f69d6529b3a29613420502e7a434..06daf6a9fc7b6af5173116ad21ee433bc08fbf22 100644 (file)
@@ -6,13 +6,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
   use Oban.Testing, repo: Pleroma.Repo
   use Pleroma.DataCase
 
-  require Pleroma.Constants
-
   alias Pleroma.Activity
   alias Pleroma.Object
   alias Pleroma.Tests.ObanHelpers
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.Transmogrifier
+  alias Pleroma.Web.ActivityPub.Utils
   alias Pleroma.Web.AdminAPI.AccountView
   alias Pleroma.Web.CommonAPI
 
@@ -108,78 +107,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert activity.data["target"] == new_user.ap_id
       assert activity.data["type"] == "Move"
     end
-
-    test "it accepts Add/Remove activities" do
-      user =
-        "test/fixtures/users_mock/user.json"
-        |> File.read!()
-        |> String.replace("{{nickname}}", "lain")
-
-      object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
-
-      object =
-        "test/fixtures/statuses/note.json"
-        |> File.read!()
-        |> String.replace("{{nickname}}", "lain")
-        |> String.replace("{{object_id}}", object_id)
-
-      object_url = "https://example.com/objects/#{object_id}"
-
-      actor = "https://example.com/users/lain"
-
-      Tesla.Mock.mock(fn
-        %{
-          method: :get,
-          url: ^actor
-        } ->
-          %Tesla.Env{
-            status: 200,
-            body: user,
-            headers: [{"content-type", "application/activity+json"}]
-          }
-
-        %{
-          method: :get,
-          url: ^object_url
-        } ->
-          %Tesla.Env{
-            status: 200,
-            body: object,
-            headers: [{"content-type", "application/activity+json"}]
-          }
-      end)
-
-      message = %{
-        "id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
-        "actor" => actor,
-        "object" => object_url,
-        "target" => "https://example.com/users/lain/collections/featured",
-        "type" => "Add",
-        "to" => [Pleroma.Constants.as_public()],
-        "cc" => ["https://example.com/users/lain/followers"]
-      }
-
-      assert {:ok, activity} = Transmogrifier.handle_incoming(message)
-      assert activity.data == message
-      user = User.get_cached_by_ap_id(actor)
-      assert user.pinned_objects[object_url]
-
-      remove = %{
-        "id" => "http://localhost:400/objects/d61d6733-e256-4fe1-ab13-1e369789423d",
-        "actor" => actor,
-        "object" => object_url,
-        "target" => "http://example.com/users/lain/collections/featured",
-        "type" => "Remove",
-        "to" => [Pleroma.Constants.as_public()],
-        "cc" => ["https://example.com/users/lain/followers"]
-      }
-
-      assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
-      assert activity.data == remove
-
-      user = refresh_record(user)
-      refute user.pinned_objects[object_url]
-    end
   end
 
   describe "prepare outgoing" do
@@ -233,8 +160,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
       {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
 
-      assert modified["@context"] ==
-               Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
+      assert modified["@context"] == Utils.make_json_ld_header()["@context"]
 
       assert modified["object"]["conversation"] == modified["context"]
     end
@@ -520,7 +446,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
           end)
       }
 
-      fixed_object = Transmogrifier.fix_explicit_addressing(object)
+      fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
       assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"]))
       refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"]
       assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"]
@@ -533,7 +459,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
         "cc" => []
       }
 
-      fixed_object = Transmogrifier.fix_explicit_addressing(object)
+      fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
       assert user.follower_address in fixed_object["to"]
       refute user.follower_address in fixed_object["cc"]
     end
@@ -547,7 +473,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
         "cc" => [user.follower_address, recipient.follower_address]
       }
 
-      fixed_object = Transmogrifier.fix_explicit_addressing(object)
+      fixed_object = Transmogrifier.fix_explicit_addressing(object, user.follower_address)
 
       assert user.follower_address in fixed_object["cc"]
       refute recipient.follower_address in fixed_object["cc"]
@@ -598,4 +524,44 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
                )
     end
   end
+
+  describe "fix_attachments/1" do
+    test "puts dimensions into attachment url field" do
+      object = %{
+        "attachment" => [
+          %{
+            "type" => "Document",
+            "name" => "Hello world",
+            "url" => "https://media.example.tld/1.jpg",
+            "width" => 880,
+            "height" => 960,
+            "mediaType" => "image/jpeg",
+            "blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
+          }
+        ]
+      }
+
+      expected = %{
+        "attachment" => [
+          %{
+            "type" => "Document",
+            "name" => "Hello world",
+            "url" => [
+              %{
+                "type" => "Link",
+                "mediaType" => "image/jpeg",
+                "href" => "https://media.example.tld/1.jpg",
+                "width" => 880,
+                "height" => 960
+              }
+            ],
+            "mediaType" => "image/jpeg",
+            "blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
+          }
+        ]
+      }
+
+      assert Transmogrifier.fix_attachments(object) == expected
+    end
+  end
 end