Metadata/Utils: use summary as description if set
[akkoma] / test / pleroma / web / metadata / providers / twitter_card_test.exs
index 1b8d27cda41f174f5ccfba1b63b95f1e508f11e1..5d7ad08ef3a6a861fd682053e0dd2594426727af 100644 (file)
@@ -39,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"
         }
       })
@@ -54,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")
@@ -65,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" => [
@@ -109,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" => [
             %{