logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

emoji_test.exs (6593B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.EmojiTest do
  5. use ExUnit.Case, async: true
  6. import ExUnit.CaptureIO
  7. import Tesla.Mock
  8. alias Mix.Tasks.Pleroma.Emoji
  9. describe "ls-packs" do
  10. test "with default manifest as url" do
  11. mock(fn
  12. %{
  13. method: :get,
  14. url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
  15. } ->
  16. %Tesla.Env{
  17. status: 200,
  18. body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
  19. }
  20. end)
  21. capture_io(fn -> Emoji.run(["ls-packs"]) end) =~
  22. "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
  23. end
  24. test "with passed manifest as file" do
  25. capture_io(fn ->
  26. Emoji.run(["ls-packs", "-m", "test/fixtures/emoji/packs/manifest.json"])
  27. end) =~ "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
  28. end
  29. end
  30. describe "get-packs" do
  31. test "download pack from default manifest" do
  32. mock(fn
  33. %{
  34. method: :get,
  35. url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
  36. } ->
  37. %Tesla.Env{
  38. status: 200,
  39. body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
  40. }
  41. %{
  42. method: :get,
  43. url: "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
  44. } ->
  45. %Tesla.Env{
  46. status: 200,
  47. body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
  48. }
  49. %{
  50. method: :get,
  51. url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/finmoji.json"
  52. } ->
  53. %Tesla.Env{
  54. status: 200,
  55. body: File.read!("test/fixtures/emoji/packs/finmoji.json")
  56. }
  57. end)
  58. assert capture_io(fn -> Emoji.run(["get-packs", "finmoji"]) end) =~ "Writing pack.json for"
  59. emoji_path =
  60. Path.join(
  61. Pleroma.Config.get!([:instance, :static_dir]),
  62. "emoji"
  63. )
  64. assert File.exists?(Path.join([emoji_path, "finmoji", "pack.json"]))
  65. on_exit(fn -> File.rm_rf!("test/instance_static/emoji/finmoji") end)
  66. end
  67. test "install local emoji pack" do
  68. assert capture_io(fn ->
  69. Emoji.run([
  70. "get-packs",
  71. "local",
  72. "--manifest",
  73. "test/instance_static/local_pack/manifest.json"
  74. ])
  75. end) =~ "Writing pack.json for"
  76. on_exit(fn -> File.rm_rf!("test/instance_static/emoji/local") end)
  77. end
  78. test "pack not found" do
  79. mock(fn
  80. %{
  81. method: :get,
  82. url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
  83. } ->
  84. %Tesla.Env{
  85. status: 200,
  86. body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
  87. }
  88. end)
  89. assert capture_io(fn -> Emoji.run(["get-packs", "not_found"]) end) =~
  90. "No pack named \"not_found\" found"
  91. end
  92. test "raise on bad sha256" do
  93. mock(fn
  94. %{
  95. method: :get,
  96. url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
  97. } ->
  98. %Tesla.Env{
  99. status: 200,
  100. body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
  101. }
  102. end)
  103. assert_raise RuntimeError, ~r/^Bad SHA256 for blobs.gg/, fn ->
  104. capture_io(fn ->
  105. Emoji.run(["get-packs", "blobs.gg", "-m", "test/fixtures/emoji/packs/manifest.json"])
  106. end)
  107. end
  108. end
  109. end
  110. describe "gen-pack" do
  111. setup do
  112. url = "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
  113. mock(fn %{
  114. method: :get,
  115. url: ^url
  116. } ->
  117. %Tesla.Env{status: 200, body: File.read!("test/fixtures/emoji/packs/blank.png.zip")}
  118. end)
  119. {:ok, url: url}
  120. end
  121. test "with default extensions", %{url: url} do
  122. name = "pack1"
  123. pack_json = "#{name}.json"
  124. files_json = "#{name}_file.json"
  125. refute File.exists?(pack_json)
  126. refute File.exists?(files_json)
  127. captured =
  128. capture_io(fn ->
  129. Emoji.run([
  130. "gen-pack",
  131. url,
  132. "--name",
  133. name,
  134. "--license",
  135. "license",
  136. "--homepage",
  137. "homepage",
  138. "--description",
  139. "description",
  140. "--files",
  141. files_json,
  142. "--extensions",
  143. ".png .gif"
  144. ])
  145. end)
  146. assert captured =~ "#{pack_json} has been created with the pack1 pack"
  147. assert captured =~ "Using .png .gif extensions"
  148. assert File.exists?(pack_json)
  149. assert File.exists?(files_json)
  150. on_exit(fn ->
  151. File.rm!(pack_json)
  152. File.rm!(files_json)
  153. end)
  154. end
  155. test "with custom extensions and update existing files", %{url: url} do
  156. name = "pack2"
  157. pack_json = "#{name}.json"
  158. files_json = "#{name}_file.json"
  159. refute File.exists?(pack_json)
  160. refute File.exists?(files_json)
  161. captured =
  162. capture_io(fn ->
  163. Emoji.run([
  164. "gen-pack",
  165. url,
  166. "--name",
  167. name,
  168. "--license",
  169. "license",
  170. "--homepage",
  171. "homepage",
  172. "--description",
  173. "description",
  174. "--files",
  175. files_json,
  176. "--extensions",
  177. " .png .gif .jpeg "
  178. ])
  179. end)
  180. assert captured =~ "#{pack_json} has been created with the pack2 pack"
  181. assert captured =~ "Using .png .gif .jpeg extensions"
  182. assert File.exists?(pack_json)
  183. assert File.exists?(files_json)
  184. captured =
  185. capture_io(fn ->
  186. Emoji.run([
  187. "gen-pack",
  188. url,
  189. "--name",
  190. name,
  191. "--license",
  192. "license",
  193. "--homepage",
  194. "homepage",
  195. "--description",
  196. "description",
  197. "--files",
  198. files_json,
  199. "--extensions",
  200. " .png .gif .jpeg "
  201. ])
  202. end)
  203. assert captured =~ "#{pack_json} has been updated with the pack2 pack"
  204. on_exit(fn ->
  205. File.rm!(pack_json)
  206. File.rm!(files_json)
  207. end)
  208. end
  209. end
  210. end