Change response format of /api/pleroma/emoji to the one that actually makes sense
authorrinpatch <rinpatch@sdf.org>
Tue, 9 Apr 2019 20:20:31 +0000 (23:20 +0300)
committerrinpatch <rinpatch@sdf.org>
Tue, 9 Apr 2019 20:20:31 +0000 (23:20 +0300)
docs/api/pleroma_api.md
lib/pleroma/web/twitter_api/controllers/util_controller.ex
test/web/twitter_api/util_controller_test.exs

index 2e8fb04d217e17060b78f3b0a9e4fbc3456b3150..6f2bc61bc6030e47ab28f96fde986a1989bdb0de 100644 (file)
@@ -10,7 +10,29 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi
 * Authentication: not required
 * Params: none
 * Response: JSON
-* Example response: `[{"kalsarikannit_f":{"tags":["Finmoji"],"image_url":"/finmoji/128px/kalsarikannit_f-128.png"}},{"perkele":{"tags":["Finmoji"],"image_url":"/finmoji/128px/perkele-128.png"}},{"blobdab":{"tags":["SomeTag"],"image_url":"/emoji/blobdab.png"}},"happiness":{"tags":["Finmoji"],"image_url":"/finmoji/128px/happiness-128.png"}}]`
+* Example response:
+```json
+{
+  "girlpower": {
+    "tags": [
+      "Finmoji"
+    ],
+    "image_url": "/finmoji/128px/girlpower-128.png"
+  },
+  "education": {
+    "tags": [
+      "Finmoji"
+    ],
+    "image_url": "/finmoji/128px/education-128.png"
+  },
+  "finnishlove": {
+    "tags": [
+      "Finmoji"
+    ],
+    "image_url": "/finmoji/128px/finnishlove-128.png"
+  }
+}
+```
 * Note: Same data as Mastodon API’s `/api/v1/custom_emojis` but in a different format
 
 ## `/api/pleroma/follow_import`
index 26407aebdca359ff4be0faf07ecd63f8fdc87f65..e6057e072716d8392477d8e5db63d4238a7c9a85 100644 (file)
@@ -286,8 +286,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
     emoji =
       Emoji.get_all()
       |> Enum.map(fn {short_code, path, tags} ->
-        %{short_code => %{image_url: path, tags: String.split(tags, ",")}}
+        {short_code, %{image_url: path, tags: String.split(tags, ",")}}
       end)
+      |> Enum.into(%{})
 
     json(conn, emoji)
   end
index 410f20f8748a653e86172c335ae08d94df22cde8..a1a5e39640c83a2d06b245c4793f029ad481be99 100644 (file)
@@ -172,22 +172,19 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
 
   describe "/api/pleroma/emoji" do
     test "returns json with custom emoji with tags", %{conn: conn} do
-      [emoji | _body] =
+      emoji =
         conn
         |> get("/api/pleroma/emoji")
         |> json_response(200)
 
-      [key] = Map.keys(emoji)
-
-      %{
-        ^key => %{
-          "image_url" => url,
-          "tags" => tags
-        }
-      } = emoji
-
-      assert is_binary(url)
-      assert is_list(tags)
+      assert Enum.all?(emoji, fn
+               {_key,
+                %{
+                  "image_url" => url,
+                  "tags" => tags
+                }} ->
+                 is_binary(url) and is_list(tags)
+             end)
     end
   end