[#1505] Improved replies-handling tests: updated Mastodon message fixture, used exact...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 10 Feb 2020 08:46:16 +0000 (11:46 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 10 Feb 2020 08:46:16 +0000 (11:46 +0300)
test/fixtures/mastodon-post-activity.json
test/web/activity_pub/transmogrifier_test.exs

index b91263431844d5346079a62d1decbd32555d3ff1..5c3d2272215caf29c2e137645c78c8548a2217df 100644 (file)
         "inReplyTo": null,
         "inReplyToAtomUri": null,
         "published": "2018-02-12T14:08:20Z",
+        "replies": {
+            "id": "http://mastodon.example.org/users/admin/statuses/99512778738411822/replies",
+            "type": "Collection",
+            "first": {
+                "type":        "CollectionPage",
+                "next": "http://mastodon.example.org/users/admin/statuses/99512778738411822/replies?min_id=99512778738411824&page=true",
+                "partOf": "http://mastodon.example.org/users/admin/statuses/99512778738411822/replies",
+                "items": [
+                    "http://mastodon.example.org/users/admin/statuses/99512778738411823",
+                    "http://mastodon.example.org/users/admin/statuses/99512778738411824"
+                ]
+            }
+        },
         "sensitive": true,
         "summary": "cw",
         "tag": [
index 7d9828d38539c4268c93a64e3c382f286f464516..bb68809b06858148967935513d0d19b486b7e47f 100644 (file)
@@ -1350,27 +1350,20 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
     end
   end
 
-  describe "`replies` handling in handle_incoming/2" do
-    setup do
+  describe "handle_incoming/2: `replies` handling:" do
+    clear_config([:activitypub, :note_replies_output_limit]) do
+      Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
+    end
+
+    test "with Mastodon-formatted `replies` collection, it schedules background fetching of items" do
       data =
-        File.read!("test/fixtures/mastodon-post-activity.json")
+        "test/fixtures/mastodon-post-activity.json"
+        |> File.read!()
         |> Poison.decode!()
 
-      items = ["https://shitposter.club/notice/2827873", "https://shitposter.club/notice/7387606"]
-      collection = %{"items" => items}
-      %{data: data, items: items, collection: collection}
-    end
+      items = get_in(data, ["object", "replies", "first", "items"])
+      assert length(items) > 0
 
-    # Mastodon wraps reply URIs in `replies->first->items`
-    test "with wrapped `replies` collection, it schedules background fetching of items", %{
-      data: data,
-      items: items,
-      collection: collection
-    } do
-      replies = %{"first" => collection}
-
-      object = Map.put(data["object"], "replies", replies)
-      data = Map.put(data, "object", object)
       {:ok, _activity} = Transmogrifier.handle_incoming(data)
 
       for id <- items do
@@ -1379,19 +1372,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       end
     end
 
-    # Pleroma outputs reply URIs as `replies->items`
-    test "it schedules background fetching of unwrapped `replies` collection items", %{
-      data: data,
-      items: items,
-      collection: collection
-    } do
-      replies = collection
+    test "with Pleroma-formatted `replies` collection, it schedules background fetching of items" do
+      user = insert(:user)
 
-      object = Map.put(data["object"], "replies", replies)
-      data = Map.put(data, "object", object)
-      {:ok, _activity} = Transmogrifier.handle_incoming(data)
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "post1"})
 
-      for id <- items do
+      {:ok, reply1} =
+        CommonAPI.post(user, %{"status" => "reply1", "in_reply_to_status_id" => activity.id})
+
+      {:ok, reply2} =
+        CommonAPI.post(user, %{"status" => "reply2", "in_reply_to_status_id" => activity.id})
+
+      replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
+
+      {:ok, federation_output} = Transmogrifier.prepare_outgoing(activity.data)
+
+      Repo.delete(activity.object)
+      Repo.delete(activity)
+
+      {:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
+
+      for id <- replies_uris do
         job_args = %{"op" => "fetch_remote", "id" => id}
         assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
       end