summaryrefslogtreecommitdiff
path: root/test/tasks/frontend_test.exs
blob: 0ca2b9a28038f893d2b321d463a6bc41cad26b8b (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.FrontendTest do
  use Pleroma.DataCase
  alias Mix.Tasks.Pleroma.Frontend

  import ExUnit.CaptureIO, only: [capture_io: 1]

  @dir "test/frontend_static_test"

  setup do
    File.mkdir_p!(@dir)
    clear_config([:instance, :static_dir], @dir)

    on_exit(fn ->
      File.rm_rf(@dir)
    end)
  end

  test "it downloads and unzips a known frontend" do
    clear_config([:frontends, :available], %{
      "pleroma" => %{
        "ref" => "fantasy",
        "name" => "pleroma",
        "build_url" => "http://gensokyo.2hu/builds/${ref}"
      }
    })

    Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
      %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
    end)

    capture_io(fn ->
      Frontend.run(["install", "pleroma"])
    end)

    assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
  end

  test "it also works given a file" do
    clear_config([:frontends, :available], %{
      "pleroma" => %{
        "ref" => "fantasy",
        "name" => "pleroma",
        "build_dir" => ""
      }
    })

    capture_io(fn ->
      Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
    end)

    assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
  end

  test "it downloads and unzips unknown frontends" do
    Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
      %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
    end)

    capture_io(fn ->
      Frontend.run([
        "install",
        "unknown",
        "--ref",
        "baka",
        "--build-url",
        "http://gensokyo.2hu/madeup.zip",
        "--build-dir",
        ""
      ])
    end)

    assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
  end
end