summaryrefslogtreecommitdiff
path: root/test/tasks/frontend_test.exs
blob: d72b03358ed53a26c7e6ea12d7873199d8514fd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
defmodule Mix.Tasks.Pleroma.FrontendTest do
  use ExUnit.Case

  import Tesla.Mock

  @path Pleroma.Config.get([:instance, :frontends_dir])

  setup do
    Mix.shell(Mix.Shell.Process)

    mock(fn
      %{
        method: :get,
        url:
          "https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/master/download?job=build"
      } ->
        %Tesla.Env{status: 200, body: File.read!("test/instance_static/dist.zip")}

      %{
        method: :get,
        url:
          "https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/develop/download?job=build"
      } ->
        %Tesla.Env{status: 200, body: File.read!("test/instance_static/dist.zip")}
    end)

    on_exit(fn ->
      Mix.shell(Mix.Shell.IO)
      {:ok, _} = File.rm_rf(@path)
    end)

    :ok
  end

  test "downloads pleroma-fe and master by default" do
    Mix.Tasks.Pleroma.Frontend.run(["download"])

    @path |> Path.expand() |> Path.join("pleroma-fe") |> check_assertions("master")
  end

  test "download special fe with reference" do
    ref = "develop"
    Mix.Tasks.Pleroma.Frontend.run(["download", "-r", ref])

    @path |> Path.expand() |> Path.join("pleroma-fe") |> check_assertions(ref)
  end

  defp check_assertions(path, ref) do
    assert_receive {:mix_shell, :info, [message]}
    assert message == "Downloading reference #{ref}"
    assert_receive {:mix_shell, :info, [message]}
    assert message == "Cleaning #{path}"
    assert_receive {:mix_shell, :info, [message]}
    assert message == "Writing to #{path}"
    assert_receive {:mix_shell, :info, ["Successfully downloaded and unpacked the frontend"]}
    assert File.exists?(path <> "/1.png")
    assert File.exists?(path <> "/2.css")
    assert File.exists?(path <> "/3.js")
  end
end