add tests for remote custom emoji

This commit is contained in:
FloatingGhost 2022-09-04 20:00:53 +01:00
parent e5fda3841c
commit f1a7123fde
2 changed files with 45 additions and 6 deletions

View File

@ -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)

View File

@ -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)