activity_pub_controller_test.exs: test posting with AP C2S uploaded media
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 17 Mar 2020 12:02:10 +0000 (13:02 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 17 Mar 2020 13:00:19 +0000 (14:00 +0100)
test/web/activity_pub/activity_pub_controller_test.exs

index bd8e0b5cc8ea1df1e59e64b61c17d68d7530e3a8..2bd494a3748aa8a29a825ac4e0bfe5c4cb6434a5 100644 (file)
@@ -1241,16 +1241,46 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
         filename: "an_image.jpg"
       }
 
-      conn =
+      object =
         conn
         |> assign(:user, user)
         |> post("/api/ap/upload_media", %{"file" => image, "description" => desc})
+        |> json_response(:created)
 
-      assert object = json_response(conn, :created)
       assert object["name"] == desc
       assert object["type"] == "Document"
       assert object["actor"] == user.ap_id
+      assert [%{"href" => object_href}] = object["url"]
+
+      activity_request = %{
+        "@context" => "https://www.w3.org/ns/activitystreams",
+        "type" => "Create",
+        "object" => %{
+          "type" => "Note",
+          "content" => "AP C2S test, attachment",
+          "attachment" => [object]
+        },
+        "to" => "https://www.w3.org/ns/activitystreams#Public",
+        "cc" => []
+      }
+
+      activity_response =
+        conn
+        |> assign(:user, user)
+        |> post("/users/#{user.nickname}/outbox", activity_request)
+        |> json_response(:created)
+
+      assert activity_response["id"]
+      assert activity_response["object"]
+      assert activity_response["actor"] == user.ap_id
+
+      assert %Object{data: %{"attachment" => [attachment]}} = Object.normalize(activity_response["object"])
+      assert attachment["type"] == "Document"
+      assert attachment["name"] == desc
+      assert [%{"href" => attachment_href}] = attachment["url"]
+      assert attachment_href == object_href
 
+      # Fails if unauthenticated
       conn
       |> post("/api/ap/upload_media", %{"file" => image, "description" => desc})
       |> json_response(403)