Metadata/Utils: use summary as description if set
[akkoma] / test / pleroma / web / metadata / providers / twitter_card_test.exs
index dbb15b79f4bb83791fc0978a8e61689735931287..5d7ad08ef3a6a861fd682053e0dd2594426727af 100644 (file)
@@ -9,6 +9,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
   alias Pleroma.User
   alias Pleroma.Web.CommonAPI
   alias Pleroma.Web.Endpoint
+  alias Pleroma.Web.MediaProxy
   alias Pleroma.Web.Metadata.Providers.TwitterCard
   alias Pleroma.Web.Metadata.Utils
   alias Pleroma.Web.Router
@@ -17,7 +18,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
 
   test "it renders twitter card for user info" do
     user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
-    avatar_url = Utils.attachment_url(User.avatar_url(user))
+    avatar_url = MediaProxy.preview_url(User.avatar_url(user))
     res = TwitterCard.build_tags(%{user: user})
 
     assert res == [
@@ -38,6 +39,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
           "actor" => user.ap_id,
           "tag" => [],
           "id" => "https://pleroma.gov/objects/whatever",
+          "summary" => "",
           "content" => "pleroma in a nutshell"
         }
       })
@@ -53,6 +55,36 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
            ] == result
   end
 
+  test "it uses summary as description if post has one" do
+    user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
+    {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
+
+    note =
+      insert(:note, %{
+        data: %{
+          "actor" => user.ap_id,
+          "tag" => [],
+          "id" => "https://pleroma.gov/objects/whatever",
+          "summary" => "Public service announcement on caffeine consumption",
+          "content" => "cofe"
+        }
+      })
+
+    result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
+
+    assert [
+             {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
+             {:meta,
+              [
+                property: "twitter:description",
+                content: "Public service announcement on caffeine consumption"
+              ], []},
+             {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
+              []},
+             {:meta, [property: "twitter:card", content: "summary"], []}
+           ] == result
+  end
+
   test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
     clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
     user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
@@ -64,6 +96,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
           "actor" => user.ap_id,
           "tag" => [],
           "id" => "https://pleroma.gov/objects/whatever",
+          "summary" => "",
           "content" => "pleroma in a nutshell",
           "sensitive" => true,
           "attachment" => [
@@ -108,6 +141,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
           "actor" => user.ap_id,
           "tag" => [],
           "id" => "https://pleroma.gov/objects/whatever",
+          "summary" => "",
           "content" => "pleroma in a nutshell",
           "attachment" => [
             %{