fix emoji controller tests
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Sat, 11 Jun 2022 13:21:50 +0000 (14:21 +0100)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Sat, 11 Jun 2022 13:21:50 +0000 (14:21 +0100)
lib/pleroma/web/activity_pub/builder.ex
lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex
test/pleroma/web/pleroma_api/controllers/emoji_reaction_controller_test.exs

index 652c257210f0a6e3622bb4cfc1f8cac7af166eb1..006e92bf40f7c556a65c3f87177c5bffe099a1a4 100644 (file)
@@ -64,25 +64,28 @@ defmodule Pleroma.Web.ActivityPub.Builder do
           |> Map.put("content", emoji)
           |> Map.put("type", "EmojiReact")
         else
-          emojo = Emoji.get(emoji)
-          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",
+          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("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}
index d89b1279468b5cf6c333237db9864b989200a2ac..d1d9363a739937f476af7f3d9b4eb6786f261b43 100644 (file)
@@ -67,7 +67,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController 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
index 28483985ce25067e263b0d497465f64382c11b45..3f47ceb755939c1832485b56034b0c0deda010fa 100644 (file)
@@ -31,7 +31,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest 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 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest 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)