add tests for remote custom emoji
This commit is contained in:
parent
e5fda3841c
commit
f1a7123fde
|
@ -79,9 +79,12 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||||
])
|
])
|
||||||
end
|
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), "@")
|
[emoji_code, instance] = String.split(Emoji.stripped_name(emoji), "@")
|
||||||
%{data: %{"reactions" => existing_reactions}} = object
|
|
||||||
|
|
||||||
matching_reaction =
|
matching_reaction =
|
||||||
Enum.find(
|
Enum.find(
|
||||||
|
@ -100,6 +103,10 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp remote_custom_emoji_react(_object, data, emoji) do
|
||||||
|
{:error, "Could not react"}
|
||||||
|
end
|
||||||
|
|
||||||
defp local_custom_emoji_react(data, emoji) do
|
defp local_custom_emoji_react(data, emoji) do
|
||||||
with %{} = emojo <- Emoji.get(emoji) do
|
with %{} = emojo <- Emoji.get(emoji) do
|
||||||
path = emojo |> Map.get(:file)
|
path = emojo |> Map.get(:file)
|
||||||
|
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_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)
|
activity = insert(:note_activity, note: note, user: user)
|
||||||
|
|
||||||
result =
|
result =
|
||||||
|
@ -27,11 +27,17 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
||||||
|> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/\u26A0")
|
|> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/\u26A0")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
# We return the status, but this our implementation detail.
|
|
||||||
assert %{"id" => id} = result
|
assert %{"id" => id} = result
|
||||||
assert to_string(activity.id) == id
|
assert to_string(activity.id) == id
|
||||||
IO.inspect(result)
|
|
||||||
assert result["pleroma"]["emoji_reactions"] == [
|
assert result["pleroma"]["emoji_reactions"] == [
|
||||||
|
%{
|
||||||
|
"name" => "👍",
|
||||||
|
"count" => 1,
|
||||||
|
"me" => true,
|
||||||
|
"url" => nil,
|
||||||
|
"account_ids" => [other_user.id]
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
"name" => "\u26A0\uFE0F",
|
"name" => "\u26A0\uFE0F",
|
||||||
"count" => 1,
|
"count" => 1,
|
||||||
|
@ -44,6 +50,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
||||||
{:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
|
{:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
|
||||||
|
|
||||||
ObanHelpers.perform_all()
|
ObanHelpers.perform_all()
|
||||||
|
|
||||||
# Reacting with a custom emoji
|
# Reacting with a custom emoji
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|
@ -52,7 +59,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
||||||
|> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/:dinosaur:")
|
|> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/:dinosaur:")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
# We return the status, but this our implementation detail.
|
|
||||||
assert %{"id" => id} = result
|
assert %{"id" => id} = result
|
||||||
assert to_string(activity.id) == id
|
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
|
# Reacting with a non-emoji
|
||||||
assert conn
|
assert conn
|
||||||
|> assign(:user, other_user)
|
|> assign(:user, other_user)
|
||||||
|
|
Loading…
Reference in New Issue