1 defmodule Mix.Tasks.Pleroma.EmojiTest do
2 use ExUnit.Case, async: true
4 import ExUnit.CaptureIO
7 alias Mix.Tasks.Pleroma.Emoji
10 test "with default manifest as url" do
14 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
18 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
22 capture_io(fn -> Emoji.run(["ls-packs"]) end) =~
23 "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
26 test "with passed manifest as file" do
28 Emoji.run(["ls-packs", "-m", "test/fixtures/emoji/packs/manifest.json"])
29 end) =~ "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
33 describe "get-packs" do
34 test "download pack from default manifest" do
38 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
42 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
47 url: "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
51 body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
56 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/finmoji.json"
60 body: File.read!("test/fixtures/emoji/packs/finmoji.json")
64 assert capture_io(fn -> Emoji.run(["get-packs", "finmoji"]) end) =~ "Writing pack.json for"
68 Pleroma.Config.get!([:instance, :static_dir]),
72 assert File.exists?(Path.join([emoji_path, "finmoji", "pack.json"]))
73 on_exit(fn -> File.rm_rf!("test/instance_static/emoji/finmoji") end)
76 test "pack not found" do
80 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
84 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
88 assert capture_io(fn -> Emoji.run(["get-packs", "not_found"]) end) =~
89 "No pack named \"not_found\" found"
92 test "raise on bad sha256" do
96 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
100 body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
104 assert_raise RuntimeError, ~r/^Bad SHA256 for blobs.gg/, fn ->
106 Emoji.run(["get-packs", "blobs.gg", "-m", "test/fixtures/emoji/packs/manifest.json"])
112 describe "gen-pack" do
114 url = "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
120 %Tesla.Env{status: 200, body: File.read!("test/fixtures/emoji/packs/blank.png.zip")}
126 test "with default extensions", %{url: url} do
128 pack_json = "#{name}.json"
129 files_json = "#{name}_file.json"
130 refute File.exists?(pack_json)
131 refute File.exists?(files_json)
153 assert captured =~ "#{pack_json} has been created with the pack1 pack"
154 assert captured =~ "Using .png .gif extensions"
156 assert File.exists?(pack_json)
157 assert File.exists?(files_json)
165 test "with custom extensions and update existing files", %{url: url} do
167 pack_json = "#{name}.json"
168 files_json = "#{name}_file.json"
169 refute File.exists?(pack_json)
170 refute File.exists?(files_json)
192 assert captured =~ "#{pack_json} has been created with the pack2 pack"
193 assert captured =~ "Using .png .gif .jpeg extensions"
195 assert File.exists?(pack_json)
196 assert File.exists?(files_json)
218 assert captured =~ "#{pack_json} has been updated with the pack2 pack"