add extra tests for builder
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Mon, 5 Sep 2022 00:24:40 +0000 (01:24 +0100)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Mon, 5 Sep 2022 00:24:40 +0000 (01:24 +0100)
lib/pleroma/emoji.ex
test/pleroma/web/activity_pub/builder_test.exs

index 24eafda4143dc06e071acc1080fc60b5e1e0c17f..dbe9abe8d54775b188afc5af2b962643fa7dc571 100644 (file)
@@ -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"))
index 640caa2b64c71899fd9cb099abf43c7d6548fd5f..98d20f02233c4219077821f72dd4d12e0b7decb5 100644 (file)
@@ -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