[Pleroma.Web.TwitterAPI.UserView]: Add mastodon-fields in "fields"
[akkoma] / test / web / twitter_api / views / user_view_test.exs
index 000c589afff4cf78bad313faa3a64b139512548e..383d7d34cf864fdbf14e5e0dfa38d0a9233c887f 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,
@@ -63,7 +87,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "background_image" => nil,
       "is_local" => true,
       "locked" => false,
-      "default_scope" => "public"
+      "default_scope" => "public",
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     assert represented == UserView.render("show.json", %{user: user})
@@ -79,9 +105,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,
@@ -102,7 +128,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "background_image" => nil,
       "is_local" => true,
       "locked" => false,
-      "default_scope" => "public"
+      "default_scope" => "public",
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -119,9 +147,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,
@@ -142,7 +170,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "background_image" => nil,
       "is_local" => true,
       "locked" => false,
-      "default_scope" => "public"
+      "default_scope" => "public",
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -166,9 +196,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,
@@ -189,7 +219,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "background_image" => nil,
       "is_local" => true,
       "locked" => false,
-      "default_scope" => "public"
+      "default_scope" => "public",
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     blocker = Repo.get(User, blocker.id)