Twitter API: Add a summary_html field.
[akkoma] / test / web / twitter_api / views / activity_view_test.exs
index 013245033786af000d5be9a9d9313efdcaee3a8f..a03f48b61e608438c6f39dd2b1b22087627cf05e 100644 (file)
@@ -41,6 +41,39 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
              "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
   end
 
+  test "a create activity with a summary containing emoji" do
+    {:ok, activity} =
+      CommonAPI.post(insert(:user), %{
+        "spoiler_text" => ":woollysocks: meow",
+        "status" => "."
+      })
+
+    result = ActivityView.render("activity.json", activity: activity)
+
+    expected = ":woollysocks: meow"
+
+    expected_html =
+      "<img height=\"32px\" width=\"32px\" alt=\"woollysocks\" title=\"woollysocks\" src=\"http://localhost:4001/finmoji/128px/woollysocks-128.png\" /> meow"
+
+    assert result["summary"] == expected
+    assert result["summary_html"] == expected_html
+  end
+
+  test "a create activity with a summary containing invalid HTML" do
+    {:ok, activity} =
+      CommonAPI.post(insert(:user), %{
+        "spoiler_text" => "<span style=\"color: magenta; font-size: 32px;\">meow</span>",
+        "status" => "."
+      })
+
+    result = ActivityView.render("activity.json", activity: activity)
+
+    expected = "meow"
+
+    assert result["summary"] == expected
+    assert result["summary_html"] == expected
+  end
+
   test "a create activity with a note" do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})
@@ -73,14 +106,15 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
       "repeat_num" => 0,
       "repeated" => false,
       "statusnet_conversation_id" => convo_id,
+      "summary" => "",
+      "summary_html" => "",
       "statusnet_html" =>
         "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
       "tags" => [],
       "text" => "Hey @shp!",
       "uri" => activity.data["object"]["id"],
       "user" => UserView.render("show.json", %{user: user}),
-      "visibility" => "direct",
-      "summary" => nil
+      "visibility" => "direct"
     }
 
     assert result == expected