logo

pleroma

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

emoji_test.exs (6434B)


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