From c3ed86cd1e6a4c704256d9dbccd077a8a4d90e84 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Sat, 11 Jun 2022 14:21:50 +0100 Subject: [PATCH] fix emoji controller tests --- lib/pleroma/web/activity_pub/builder.ex | 37 ++++++++++--------- .../controllers/emoji_reaction_controller.ex | 2 +- .../emoji_reaction_controller_test.exs | 12 +++++- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/pleroma/web/activity_pub/builder.ex b/lib/pleroma/web/activity_pub/builder.ex index 652c25721..006e92bf4 100644 --- a/lib/pleroma/web/activity_pub/builder.ex +++ b/lib/pleroma/web/activity_pub/builder.ex @@ -64,25 +64,28 @@ def emoji_react(actor, object, emoji) do |> Map.put("content", emoji) |> Map.put("type", "EmojiReact") else - emojo = Emoji.get(emoji) - path = emojo |> Map.get(:file) - url = "#{Endpoint.url()}#{path}" + with %{} = emojo <- Emoji.get(emoji) do + path = emojo |> Map.get(:file) + url = "#{Endpoint.url()}#{path}" - data - |> Map.put("content", emoji) - |> Map.put("type", "EmojiReact") - |> Map.put("tag", [ - %{} - |> Map.put("id", url) - |> Map.put("type", "Emoji") - |> Map.put("name", emojo.code) - |> Map.put( - "icon", + data + |> Map.put("content", emoji) + |> Map.put("type", "EmojiReact") + |> Map.put("tag", [ %{} - |> Map.put("type", "Image") - |> Map.put("url", url) - ) - ]) + |> Map.put("id", url) + |> Map.put("type", "Emoji") + |> Map.put("name", emojo.code) + |> Map.put( + "icon", + %{} + |> Map.put("type", "Image") + |> Map.put("url", url) + ) + ]) + else + _ -> {:error, "Emoji does not exist"} + end end {:ok, data, meta} diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex index d89b12794..d1d9363a7 100644 --- a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex @@ -67,7 +67,7 @@ def filter_allowed_users(reactions, user, with_muted) do end defp filter(reactions, %{emoji: emoji}) when is_binary(emoji) do - Enum.filter(reactions, fn [e, _] -> e == emoji end) + Enum.filter(reactions, fn [e, _, _] -> e == emoji end) end defp filter(reactions, _), do: reactions diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs index 28483985c..3f47ceb75 100644 --- a/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs @@ -31,7 +31,7 @@ test "PUT /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do assert to_string(activity.id) == id assert result["pleroma"]["emoji_reactions"] == [ - %{"name" => "☕", "count" => 1, "me" => true} + %{"name" => "☕", "count" => 1, "me" => true, "url" => nil} ] # Reacting with a non-emoji @@ -181,7 +181,15 @@ test "GET /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅") {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") - assert [%{"name" => "🎅", "count" => 1, "accounts" => [represented_user], "me" => false}] = + assert [ + %{ + "name" => "🎅", + "count" => 1, + "accounts" => [represented_user], + "me" => false, + "url" => nil + } + ] = conn |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions/🎅") |> json_response_and_validate_schema(200)