From f1a7123fdec3f51a397f3c3ef4a9b243f7255fb1 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Sun, 4 Sep 2022 20:00:53 +0100 Subject: [PATCH] add tests for remote custom emoji --- lib/pleroma/web/activity_pub/builder.ex | 11 ++++- .../emoji_reaction_controller_test.exs | 40 +++++++++++++++++-- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/builder.ex b/lib/pleroma/web/activity_pub/builder.ex index 67bd461a2..71ccbdef5 100644 --- a/lib/pleroma/web/activity_pub/builder.ex +++ b/lib/pleroma/web/activity_pub/builder.ex @@ -79,9 +79,12 @@ defmodule Pleroma.Web.ActivityPub.Builder do ]) end - defp remote_custom_emoji_react(object, data, emoji) do + defp remote_custom_emoji_react( + %{data: %{"reactions" => existing_reactions}} = object, + data, + emoji + ) do [emoji_code, instance] = String.split(Emoji.stripped_name(emoji), "@") - %{data: %{"reactions" => existing_reactions}} = object matching_reaction = Enum.find( @@ -100,6 +103,10 @@ defmodule Pleroma.Web.ActivityPub.Builder do end end + defp remote_custom_emoji_react(_object, data, emoji) do + {:error, "Could not react"} + end + defp local_custom_emoji_react(data, emoji) do with %{} = emojo <- Emoji.get(emoji) do path = emojo |> Map.get(:file) 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 8ff2ef51f..9fb683262 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 @@ -17,7 +17,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do user = insert(:user) other_user = insert(:user) - note = insert(:note, user: user, reactions: %{reactions: %{"👍" => [other_user.ap_id]}}) + note = insert(:note, user: user, data: %{"reactions" => [["👍", [other_user.ap_id], nil]]}) activity = insert(:note_activity, note: note, user: user) result = @@ -27,11 +27,17 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/\u26A0") |> json_response_and_validate_schema(200) - # We return the status, but this our implementation detail. assert %{"id" => id} = result assert to_string(activity.id) == id - IO.inspect(result) + assert result["pleroma"]["emoji_reactions"] == [ + %{ + "name" => "👍", + "count" => 1, + "me" => true, + "url" => nil, + "account_ids" => [other_user.id] + }, %{ "name" => "\u26A0\uFE0F", "count" => 1, @@ -44,6 +50,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"}) ObanHelpers.perform_all() + # Reacting with a custom emoji result = conn @@ -52,7 +59,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/:dinosaur:") |> json_response_and_validate_schema(200) - # We return the status, but this our implementation detail. assert %{"id" => id} = result assert to_string(activity.id) == id @@ -66,6 +72,32 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do } ] + # Reacting with a remote emoji + note = + insert(:note, + user: user, + data: %{"reactions" => [["wow", [other_user.ap_id], "https://remote/emoji/wow"]]} + ) + + activity = insert(:note_activity, note: note, user: user) + + result = + conn + |> assign(:user, user) + |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:statuses"])) + |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/:wow@remote:") + |> json_response(200) + + assert result["pleroma"]["emoji_reactions"] == [ + %{ + "name" => "wow@remote", + "count" => 2, + "me" => true, + "url" => "https://remote/emoji/wow", + "account_ids" => [user.id, other_user.id] + } + ] + # Reacting with a non-emoji assert conn |> assign(:user, other_user)