commit: bf134664b437a9b45a193135d708cef8e803595b
parent 2fcb90f3697d3c15e1aebab89b7eaaa69a315c0b
Author: Lain Soykaf <lain@lain.com>
Date: Fri, 28 Feb 2025 12:53:15 +0400
PackTest: Add test for skipping emoji
Diffstat:
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/lib/pleroma/user/backup.ex b/lib/pleroma/user/backup.ex
@@ -23,7 +23,6 @@ defmodule Pleroma.User.Backup do
alias Pleroma.Web.ActivityPub.UserView
alias Pleroma.Workers.BackupWorker
alias Pleroma.SafeZip
- alias Pleroma.Upload
@type t :: %__MODULE__{}
diff --git a/test/pleroma/emoji/pack_test.exs b/test/pleroma/emoji/pack_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Emoji.PackTest do
use Pleroma.DataCase
alias Pleroma.Emoji.Pack
+ alias Pleroma.Emoji
@emoji_path Path.join(
Pleroma.Config.get!([:instance, :static_dir]),
@@ -53,6 +54,63 @@ defmodule Pleroma.Emoji.PackTest do
assert updated_pack.files_count == 5
end
+
+ test "skips existing emojis when adding from zip file", %{pack: pack} do
+ # First, let's create a test pack with a "bear" emoji
+ test_pack_path = Path.join(@emoji_path, "test_bear_pack")
+ File.mkdir_p(test_pack_path)
+
+ # Create a pack.json file
+ File.write!(Path.join(test_pack_path, "pack.json"), """
+ {
+ "files": { "bear": "bear.png" },
+ "pack": {
+ "description": "Bear Pack", "homepage": "https://pleroma.social",
+ "license": "Test license", "share-files": true
+ }}
+ """)
+
+ # Copy a test image to use as the bear emoji
+ File.cp!(
+ Path.absname("test/instance_static/emoji/test_pack/blank.png"),
+ Path.join(test_pack_path, "bear.png")
+ )
+
+ # Load the pack to register the "bear" emoji in the global registry
+ {:ok, _bear_pack} = Pleroma.Emoji.Pack.load_pack("test_bear_pack")
+
+ # Reload emoji to make sure the bear emoji is in the global registry
+ Emoji.reload()
+
+ # Verify that the bear emoji exists in the global registry
+ assert Emoji.exist?("bear")
+
+ # Now try to add a zip file that contains an emoji with the same shortcode
+ file = %Plug.Upload{
+ content_type: "application/zip",
+ filename: "emojis.zip",
+ path: Path.absname("test/fixtures/emojis.zip")
+ }
+
+ {:ok, updated_pack} = Pack.add_file(pack, nil, nil, file)
+
+ # Verify that the "bear" emoji was skipped
+ refute Map.has_key?(updated_pack.files, "bear")
+
+ # Other emojis should be added
+ assert Map.has_key?(updated_pack.files, "a_trusted_friend-128")
+ assert Map.has_key?(updated_pack.files, "auroraborealis")
+ assert Map.has_key?(updated_pack.files, "baby_in_a_box")
+ assert Map.has_key?(updated_pack.files, "bear-128")
+
+ # Total count should be 4 (all emojis except "bear")
+ assert updated_pack.files_count == 4
+
+ # Clean up the test pack
+ on_exit(fn ->
+ File.rm_rf!(test_pack_path)
+ end)
+ end
end
test "returns error when zip file is bad", %{pack: pack} do