From b57b43027cf958d3a3a82b95f155ae27b235b543 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 9 Apr 2019 23:20:31 +0300 Subject: [PATCH] Change response format of /api/pleroma/emoji to the one that actually makes sense --- docs/api/pleroma_api.md | 24 ++++++++++++++++++- .../controllers/util_controller.ex | 3 ++- test/web/twitter_api/util_controller_test.exs | 21 +++++++--------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/docs/api/pleroma_api.md b/docs/api/pleroma_api.md index 2e8fb04d2..6f2bc61bc 100644 --- a/docs/api/pleroma_api.md +++ b/docs/api/pleroma_api.md @@ -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` diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 26407aebd..e6057e072 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -286,8 +286,9 @@ def emoji(conn, _params) 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 diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 410f20f87..a1a5e3964 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -172,22 +172,19 @@ test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} d 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