Add tests for emoji in user profiles
authoreal <eal@waifu.club>
Wed, 8 Aug 2018 06:24:50 +0000 (09:24 +0300)
committereal <eal@waifu.club>
Wed, 8 Aug 2018 06:24:50 +0000 (09:24 +0300)
Also use the correct field in TwitterAPI...

lib/pleroma/web/twitter_api/views/user_view.ex
test/web/mastodon_api/account_view_test.exs
test/web/twitter_api/views/user_view_test.exs

index 30cf266bdd17f2ae8cb7abec5459748e0cce6d11..30aaaf1ceb87f90630363c00bfd78b18d9162bf2 100644 (file)
@@ -50,6 +50,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
       "friends_count" => user_info[:following_count],
       "id" => user.id,
       "name" => user.name,
+      "name_html" => Formatter.emojify(user.name, emoji),
       "profile_image_url" => image,
       "profile_image_url_https" => image,
       "profile_image_url_profile_size" => image,
@@ -58,7 +59,6 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
         "delete_others_notice" => !!user.info["is_moderator"]
       },
       "screen_name" => user.nickname,
-      "screen_name_html" => Formatter.emojify(user.nickname, emoji),
       "statuses_count" => user_info[:note_count],
       "statusnet_profile_url" => user.ap_id,
       "cover_photo" => User.banner_url(user) |> MediaProxy.url(),
index b93418b3fbf0293dfc60602a1aaa38d8f5c933e4..8bf194e6b98e8a81f6e6c8c56c78b6456efc5168 100644 (file)
@@ -5,10 +5,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
   alias Pleroma.User
 
   test "Represent a user account" do
+    source_data = %{
+      "tag" => [
+        %{
+          "type" => "Emoji",
+          "icon" => %{"url" => "/file.png"},
+          "name" => ":karjalanpiirakka:"
+        }
+      ]
+    }
+
     user =
       insert(:user, %{
-        info: %{"note_count" => 5, "follower_count" => 3},
+        info: %{"note_count" => 5, "follower_count" => 3, "source_data" => source_data},
         nickname: "shp@shitposter.club",
+        name: ":karjalanpiirakka: shp",
         inserted_at: ~N[2017-08-15 15:47:06.597036]
       })
 
@@ -28,7 +39,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       avatar_static: "http://localhost:4001/images/avi.png",
       header: "http://localhost:4001/images/banner.png",
       header_static: "http://localhost:4001/images/banner.png",
-      emojis: [],
+      emojis: [
+        %{
+          "static_url" => "/file.png",
+          "url" => "/file.png",
+          "shortcode" => "karjalanpiirakka",
+          "visible_in_picker" => false
+        }
+      ],
       fields: [],
       source: %{
         note: "",
index 000c589afff4cf78bad313faa3a64b139512548e..fefb6bdcc32307be17db10d3bfea46c83eec70c7 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,7 +64,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
-      "screen_name_html" => user.nickname,
+      "name_html" => user.name,
       "description" => HtmlSanitizeEx.strip_tags(user.bio),
       "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
@@ -79,7 +103,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
-      "screen_name_html" => user.nickname,
+      "name_html" => user.name,
       "description" => HtmlSanitizeEx.strip_tags(user.bio),
       "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
@@ -119,7 +143,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => follower.id,
       "name" => follower.name,
       "screen_name" => follower.nickname,
-      "screen_name_html" => follower.nickname,
+      "name_html" => follower.name,
       "description" => HtmlSanitizeEx.strip_tags(follower.bio),
       "description_html" => HtmlSanitizeEx.strip_tags(follower.bio),
       "created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
@@ -166,7 +190,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
-      "screen_name_html" => user.nickname,
+      "name_html" => user.name,
       "description" => HtmlSanitizeEx.strip_tags(user.bio),
       "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),