diff options
Diffstat (limited to 'test/tasks')
| -rw-r--r-- | test/tasks/config_test.exs | 4 | ||||
| -rw-r--r-- | test/tasks/emoji_test.exs | 226 | ||||
| -rw-r--r-- | test/tasks/robots_txt_test.exs | 2 | 
3 files changed, 228 insertions, 4 deletions
| diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index a6c0de351..3dee4f082 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -20,9 +20,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do      :ok    end -  clear_config_all(:configurable_from_database) do -    Pleroma.Config.put(:configurable_from_database, true) -  end +  setup_all do: clear_config(:configurable_from_database, true)    test "error if file with custom settings doesn't exist" do      Mix.Tasks.Pleroma.Config.migrate_to_db("config/not_existance_config_file.exs") diff --git a/test/tasks/emoji_test.exs b/test/tasks/emoji_test.exs new file mode 100644 index 000000000..f5de3ef0e --- /dev/null +++ b/test/tasks/emoji_test.exs @@ -0,0 +1,226 @@ +defmodule Mix.Tasks.Pleroma.EmojiTest do +  use ExUnit.Case, async: true + +  import ExUnit.CaptureIO +  import Tesla.Mock + +  alias Mix.Tasks.Pleroma.Emoji + +  describe "ls-packs" do +    test "with default manifest as url" do +      mock(fn +        %{ +          method: :get, +          url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json" +        } -> +          %Tesla.Env{ +            status: 200, +            body: File.read!("test/fixtures/emoji/packs/default-manifest.json") +          } +      end) + +      capture_io(fn -> Emoji.run(["ls-packs"]) end) =~ +        "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip" +    end + +    test "with passed manifest as file" do +      capture_io(fn -> +        Emoji.run(["ls-packs", "-m", "test/fixtures/emoji/packs/manifest.json"]) +      end) =~ "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip" +    end +  end + +  describe "get-packs" do +    test "download pack from default manifest" do +      mock(fn +        %{ +          method: :get, +          url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json" +        } -> +          %Tesla.Env{ +            status: 200, +            body: File.read!("test/fixtures/emoji/packs/default-manifest.json") +          } + +        %{ +          method: :get, +          url: "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip" +        } -> +          %Tesla.Env{ +            status: 200, +            body: File.read!("test/fixtures/emoji/packs/blank.png.zip") +          } + +        %{ +          method: :get, +          url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/finmoji.json" +        } -> +          %Tesla.Env{ +            status: 200, +            body: File.read!("test/fixtures/emoji/packs/finmoji.json") +          } +      end) + +      assert capture_io(fn -> Emoji.run(["get-packs", "finmoji"]) end) =~ "Writing pack.json for" + +      emoji_path = +        Path.join( +          Pleroma.Config.get!([:instance, :static_dir]), +          "emoji" +        ) + +      assert File.exists?(Path.join([emoji_path, "finmoji", "pack.json"])) +      on_exit(fn -> File.rm_rf!("test/instance_static/emoji/finmoji") end) +    end + +    test "pack not found" do +      mock(fn +        %{ +          method: :get, +          url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json" +        } -> +          %Tesla.Env{ +            status: 200, +            body: File.read!("test/fixtures/emoji/packs/default-manifest.json") +          } +      end) + +      assert capture_io(fn -> Emoji.run(["get-packs", "not_found"]) end) =~ +               "No pack named \"not_found\" found" +    end + +    test "raise on bad sha256" do +      mock(fn +        %{ +          method: :get, +          url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip" +        } -> +          %Tesla.Env{ +            status: 200, +            body: File.read!("test/fixtures/emoji/packs/blank.png.zip") +          } +      end) + +      assert_raise RuntimeError, ~r/^Bad SHA256 for blobs.gg/, fn -> +        capture_io(fn -> +          Emoji.run(["get-packs", "blobs.gg", "-m", "test/fixtures/emoji/packs/manifest.json"]) +        end) +      end +    end +  end + +  describe "gen-pack" do +    setup do +      url = "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip" + +      mock(fn %{ +                method: :get, +                url: ^url +              } -> +        %Tesla.Env{status: 200, body: File.read!("test/fixtures/emoji/packs/blank.png.zip")} +      end) + +      {:ok, url: url} +    end + +    test "with default extensions", %{url: url} do +      name = "pack1" +      pack_json = "#{name}.json" +      files_json = "#{name}_file.json" +      refute File.exists?(pack_json) +      refute File.exists?(files_json) + +      captured = +        capture_io(fn -> +          Emoji.run([ +            "gen-pack", +            url, +            "--name", +            name, +            "--license", +            "license", +            "--homepage", +            "homepage", +            "--description", +            "description", +            "--files", +            files_json, +            "--extensions", +            ".png .gif" +          ]) +        end) + +      assert captured =~ "#{pack_json} has been created with the pack1 pack" +      assert captured =~ "Using .png .gif extensions" + +      assert File.exists?(pack_json) +      assert File.exists?(files_json) + +      on_exit(fn -> +        File.rm!(pack_json) +        File.rm!(files_json) +      end) +    end + +    test "with custom extensions and update existing files", %{url: url} do +      name = "pack2" +      pack_json = "#{name}.json" +      files_json = "#{name}_file.json" +      refute File.exists?(pack_json) +      refute File.exists?(files_json) + +      captured = +        capture_io(fn -> +          Emoji.run([ +            "gen-pack", +            url, +            "--name", +            name, +            "--license", +            "license", +            "--homepage", +            "homepage", +            "--description", +            "description", +            "--files", +            files_json, +            "--extensions", +            " .png   .gif    .jpeg " +          ]) +        end) + +      assert captured =~ "#{pack_json} has been created with the pack2 pack" +      assert captured =~ "Using .png .gif .jpeg extensions" + +      assert File.exists?(pack_json) +      assert File.exists?(files_json) + +      captured = +        capture_io(fn -> +          Emoji.run([ +            "gen-pack", +            url, +            "--name", +            name, +            "--license", +            "license", +            "--homepage", +            "homepage", +            "--description", +            "description", +            "--files", +            files_json, +            "--extensions", +            " .png   .gif    .jpeg " +          ]) +        end) + +      assert captured =~ "#{pack_json} has been updated with the pack2 pack" + +      on_exit(fn -> +        File.rm!(pack_json) +        File.rm!(files_json) +      end) +    end +  end +end diff --git a/test/tasks/robots_txt_test.exs b/test/tasks/robots_txt_test.exs index e03c9c192..7040a0e4e 100644 --- a/test/tasks/robots_txt_test.exs +++ b/test/tasks/robots_txt_test.exs @@ -7,7 +7,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do    use Pleroma.Tests.Helpers    alias Mix.Tasks.Pleroma.RobotsTxt -  clear_config([:instance, :static_dir]) +  setup do: clear_config([:instance, :static_dir])    test "creates new dir" do      path = "test/fixtures/new_dir/" | 
