Merge branch 'hotfix_broken_likes' into 'develop'
[akkoma] / test / web / twitter_api / views / user_view_test.exs
index 000c589afff4cf78bad313faa3a64b139512548e..7075a237090f1c1dba050c16eac3332ce92d451a 100644 (file)
@@ -20,6 +20,30 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
     assert represented["profile_image_url"] == image
   end
 
+  test "A user with emoji in username", %{user: user} do
+    expected =
+      "<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
+
+    user = %{
+      user
+      | info: %{
+          "source_data" => %{
+            "tag" => [
+              %{
+                "type" => "Emoji",
+                "icon" => %{"url" => "/file.png"},
+                "name" => ":karjalanpiirakka:"
+              }
+            ]
+          }
+        }
+    }
+
+    user = %{user | name: ":karjalanpiirakka: man"}
+    represented = UserView.render("show.json", %{user: user})
+    assert represented["name_html"] == expected
+  end
+
   test "A user" do
     note_activity = insert(:note_activity)
     user = User.get_cached_by_ap_id(note_activity.data["actor"])
@@ -40,9 +64,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
-      "screen_name_html" => user.nickname,
-      "description" => HtmlSanitizeEx.strip_tags(user.bio),
-      "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
+      "name_html" => user.name,
+      "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
+      "description_html" => HtmlSanitizeEx.basic_html(user.bio),
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
       "favourites_count" => 0,
       "statuses_count" => 1,
@@ -79,9 +103,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
-      "screen_name_html" => user.nickname,
-      "description" => HtmlSanitizeEx.strip_tags(user.bio),
-      "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
+      "name_html" => user.name,
+      "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
+      "description_html" => HtmlSanitizeEx.basic_html(user.bio),
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
       "favourites_count" => 0,
       "statuses_count" => 0,
@@ -119,9 +143,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => follower.id,
       "name" => follower.name,
       "screen_name" => follower.nickname,
-      "screen_name_html" => follower.nickname,
-      "description" => HtmlSanitizeEx.strip_tags(follower.bio),
-      "description_html" => HtmlSanitizeEx.strip_tags(follower.bio),
+      "name_html" => follower.name,
+      "description" => HtmlSanitizeEx.strip_tags(follower.bio |> String.replace("<br>", "\n")),
+      "description_html" => HtmlSanitizeEx.basic_html(follower.bio),
       "created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
       "favourites_count" => 0,
       "statuses_count" => 0,
@@ -166,9 +190,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
-      "screen_name_html" => user.nickname,
-      "description" => HtmlSanitizeEx.strip_tags(user.bio),
-      "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
+      "name_html" => user.name,
+      "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
+      "description_html" => HtmlSanitizeEx.basic_html(user.bio),
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
       "favourites_count" => 0,
       "statuses_count" => 0,