From: FloatingGhost Date: Mon, 5 Sep 2022 00:24:40 +0000 (+0100) Subject: add extra tests for builder X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=f6304cfd7836e646df013e6230304b5915b92899;p=akkoma add extra tests for builder --- diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index 24eafda41..dbe9abe8d 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -188,6 +188,11 @@ defmodule Pleroma.Emoji do def emoji_url(_), do: nil + def emoji_name_with_instance(name, url) do + url = url |> URI.parse() |> Map.get(:host) + "#{name}@#{url}" + end + emoji_qualification_map = emojis |> Enum.filter(&String.contains?(&1, "\uFE0F")) diff --git a/test/pleroma/web/activity_pub/builder_test.exs b/test/pleroma/web/activity_pub/builder_test.exs index 640caa2b6..98d20f022 100644 --- a/test/pleroma/web/activity_pub/builder_test.exs +++ b/test/pleroma/web/activity_pub/builder_test.exs @@ -48,4 +48,57 @@ defmodule Pleroma.Web.ActivityPub.BuilderTest do assert {:ok, ^expected, []} = Builder.note(draft) end end + + describe "emoji_react/1" do + test "unicode emoji" do + user = insert(:user) + note = insert(:note) + + assert {:ok, %{"content" => "👍", "type" => "EmojiReact"}, []} = + Builder.emoji_react(user, note, "👍") + end + + test "custom emoji" do + user = insert(:user) + note = insert(:note) + + assert {:ok, + %{ + "content" => ":dinosaur:", + "type" => "EmojiReact", + "tag" => [ + %{ + "name" => ":dinosaur:", + "id" => "http://localhost:4001/emoji/dino walking.gif", + "icon" => %{ + "type" => "Image", + "url" => "http://localhost:4001/emoji/dino walking.gif" + } + } + ] + }, []} = Builder.emoji_react(user, note, ":dinosaur:") + end + + test "remote custom emoji" do + user = insert(:user) + other_user = insert(:user, local: false) + note = insert(:note, data: %{"reactions" => [["wow", [other_user.ap_id], "https://remote/emoji/wow"]]}) + + assert {:ok, + %{ + "content" => ":wow:", + "type" => "EmojiReact", + "tag" => [ + %{ + "name" => ":wow:", + "id" => "https://remote/emoji/wow", + "icon" => %{ + "type" => "Image", + "url" => "https://remote/emoji/wow" + } + } + ] + }, []} = Builder.emoji_react(user, note, ":wow@remote:") + end + end end