1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.EmojiTest do
6 use ExUnit.Case, async: true
8 import ExUnit.CaptureIO
11 alias Mix.Tasks.Pleroma.Emoji
13 describe "ls-packs" do
14 test "with default manifest as url" do
18 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
22 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
26 capture_io(fn -> Emoji.run(["ls-packs"]) end) =~
27 "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
30 test "with passed manifest as file" do
32 Emoji.run(["ls-packs", "-m", "test/fixtures/emoji/packs/manifest.json"])
33 end) =~ "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
37 describe "get-packs" do
38 test "download pack from default manifest" do
42 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
46 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
51 url: "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
55 body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
60 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/finmoji.json"
64 body: File.read!("test/fixtures/emoji/packs/finmoji.json")
68 assert capture_io(fn -> Emoji.run(["get-packs", "finmoji"]) end) =~ "Writing pack.json for"
72 Pleroma.Config.get!([:instance, :static_dir]),
76 assert File.exists?(Path.join([emoji_path, "finmoji", "pack.json"]))
77 on_exit(fn -> File.rm_rf!("test/instance_static/emoji/finmoji") end)
80 test "install local emoji pack" do
81 assert capture_io(fn ->
86 "test/instance_static/local_pack/manifest.json"
88 end) =~ "Writing pack.json for"
90 on_exit(fn -> File.rm_rf!("test/instance_static/emoji/local") end)
93 test "pack not found" do
97 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
101 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
105 assert capture_io(fn -> Emoji.run(["get-packs", "not_found"]) end) =~
106 "No pack named \"not_found\" found"
109 test "raise on bad sha256" do
113 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
117 body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
121 assert_raise RuntimeError, ~r/^Bad SHA256 for blobs.gg/, fn ->
123 Emoji.run(["get-packs", "blobs.gg", "-m", "test/fixtures/emoji/packs/manifest.json"])
129 describe "gen-pack" do
131 url = "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
137 %Tesla.Env{status: 200, body: File.read!("test/fixtures/emoji/packs/blank.png.zip")}
143 test "with default extensions", %{url: url} do
145 pack_json = "#{name}.json"
146 files_json = "#{name}_file.json"
147 refute File.exists?(pack_json)
148 refute File.exists?(files_json)
170 assert captured =~ "#{pack_json} has been created with the pack1 pack"
171 assert captured =~ "Using .png .gif extensions"
173 assert File.exists?(pack_json)
174 assert File.exists?(files_json)
182 test "with custom extensions and update existing files", %{url: url} do
184 pack_json = "#{name}.json"
185 files_json = "#{name}_file.json"
186 refute File.exists?(pack_json)
187 refute File.exists?(files_json)
209 assert captured =~ "#{pack_json} has been created with the pack2 pack"
210 assert captured =~ "Using .png .gif .jpeg extensions"
212 assert File.exists?(pack_json)
213 assert File.exists?(files_json)
235 assert captured =~ "#{pack_json} has been updated with the pack2 pack"