Merge remote-tracking branch 'MAIN/develop' into feature/jobs
[akkoma] / test / web / mastodon_api / mastodon_api_controller_test.exs
index b4870e0b2a198716c97e8c7dc6d911c512075ecb..1a5eb090c44e1a95fea85c7d19be9b6d964d4305 100644 (file)
@@ -136,6 +136,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     assert Repo.get(Activity, id)
   end
 
+  test "posting a status with OGP link preview", %{conn: conn} do
+    user = insert(:user)
+
+    conn =
+      conn
+      |> assign(:user, user)
+      |> post("/api/v1/statuses", %{
+        "status" => "http://example.com/ogp"
+      })
+
+    assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
+    assert Repo.get(Activity, id)
+  end
+
   test "posting a direct status", %{conn: conn} do
     user1 = insert(:user)
     user2 = insert(:user)
@@ -1048,12 +1062,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     user = insert(:user)
 
     {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
-    {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test1"})
+    {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
     {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
 
     any_test =
       conn
-      |> get("/api/v1/timelines/tag/test", %{"any" => ["none"]})
+      |> get("/api/v1/timelines/tag/test", %{"any" => ["test1"]})
 
     [status_none, status_test1, status_test] = json_response(any_test, 200)
 
@@ -1065,7 +1079,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       conn
       |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
 
-    assert [status_test1, status_test] == json_response(restricted_test, 200)
+    assert [status_test1] == json_response(restricted_test, 200)
 
     all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]})
 
@@ -1651,5 +1665,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
                |> post("/api/v1/statuses/#{activity_two.id}/pin")
                |> json_response(400)
     end
+
+    test "Status rich-media Card", %{conn: conn, user: user} do
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
+
+      response =
+        conn
+        |> get("/api/v1/statuses/#{activity.id}/card")
+        |> json_response(200)
+
+      assert response == %{
+               "image" => "http://ia.media-imdb.com/images/rock.jpg",
+               "provider_name" => "www.imdb.com",
+               "provider_url" => "http://www.imdb.com",
+               "title" => "The Rock",
+               "type" => "link",
+               "url" => "http://www.imdb.com/title/tt0117500/",
+               "description" => nil,
+               "pleroma" => %{
+                 "opengraph" => %{
+                   "image" => "http://ia.media-imdb.com/images/rock.jpg",
+                   "title" => "The Rock",
+                   "type" => "video.movie",
+                   "url" => "http://www.imdb.com/title/tt0117500/"
+                 }
+               }
+             }
+    end
   end
 end