logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

pack_test.exs (2576B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Emoji.PackTest do
  5. use ExUnit.Case, async: true
  6. alias Pleroma.Emoji.Pack
  7. @emoji_path Path.join(
  8. Pleroma.Config.get!([:instance, :static_dir]),
  9. "emoji"
  10. )
  11. setup do
  12. pack_path = Path.join(@emoji_path, "dump_pack")
  13. File.mkdir(pack_path)
  14. File.write!(Path.join(pack_path, "pack.json"), """
  15. {
  16. "files": { },
  17. "pack": {
  18. "description": "Dump pack", "homepage": "https://pleroma.social",
  19. "license": "Test license", "share-files": true
  20. }}
  21. """)
  22. {:ok, pack} = Pleroma.Emoji.Pack.load_pack("dump_pack")
  23. on_exit(fn ->
  24. File.rm_rf!(pack_path)
  25. end)
  26. {:ok, pack: pack}
  27. end
  28. describe "add_file/4" do
  29. test "add emojies from zip file", %{pack: pack} do
  30. file = %Plug.Upload{
  31. content_type: "application/zip",
  32. filename: "emojis.zip",
  33. path: Path.absname("test/fixtures/emojis.zip")
  34. }
  35. {:ok, updated_pack} = Pack.add_file(pack, nil, nil, file)
  36. assert updated_pack.files == %{
  37. "a_trusted_friend-128" => "128px/a_trusted_friend-128.png",
  38. "auroraborealis" => "auroraborealis.png",
  39. "baby_in_a_box" => "1000px/baby_in_a_box.png",
  40. "bear" => "1000px/bear.png",
  41. "bear-128" => "128px/bear-128.png"
  42. }
  43. assert updated_pack.files_count == 5
  44. end
  45. end
  46. test "returns error when zip file is bad", %{pack: pack} do
  47. file = %Plug.Upload{
  48. content_type: "application/zip",
  49. filename: "emojis.zip",
  50. path: Path.absname("test/instance_static/emoji/test_pack/blank.png")
  51. }
  52. assert Pack.add_file(pack, nil, nil, file) == {:error, :einval}
  53. end
  54. test "returns pack when zip file is empty", %{pack: pack} do
  55. file = %Plug.Upload{
  56. content_type: "application/zip",
  57. filename: "emojis.zip",
  58. path: Path.absname("test/fixtures/empty.zip")
  59. }
  60. {:ok, updated_pack} = Pack.add_file(pack, nil, nil, file)
  61. assert updated_pack == pack
  62. end
  63. test "add emoji file", %{pack: pack} do
  64. file = %Plug.Upload{
  65. filename: "blank.png",
  66. path: "#{@emoji_path}/test_pack/blank.png"
  67. }
  68. {:ok, updated_pack} = Pack.add_file(pack, "test_blank", "test_blank.png", file)
  69. assert updated_pack.files == %{
  70. "test_blank" => "test_blank.png"
  71. }
  72. assert updated_pack.files_count == 1
  73. end
  74. end