Merge branch 'feat/rich-media-head' into 'develop'
[akkoma] / test / tasks / frontend_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.FrontendTest do
6 use Pleroma.DataCase
7 alias Mix.Tasks.Pleroma.Frontend
8
9 import ExUnit.CaptureIO, only: [capture_io: 1]
10
11 @dir "test/frontend_static_test"
12
13 setup do
14 File.mkdir_p!(@dir)
15 clear_config([:instance, :static_dir], @dir)
16
17 on_exit(fn ->
18 File.rm_rf(@dir)
19 end)
20 end
21
22 test "it downloads and unzips a known frontend" do
23 clear_config([:frontends, :available], %{
24 "pleroma" => %{
25 "ref" => "fantasy",
26 "name" => "pleroma",
27 "build_url" => "http://gensokyo.2hu/builds/${ref}"
28 }
29 })
30
31 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
32 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
33 end)
34
35 capture_io(fn ->
36 Frontend.run(["install", "pleroma"])
37 end)
38
39 assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
40 end
41
42 test "it also works given a file" do
43 clear_config([:frontends, :available], %{
44 "pleroma" => %{
45 "ref" => "fantasy",
46 "name" => "pleroma",
47 "build_dir" => ""
48 }
49 })
50
51 capture_io(fn ->
52 Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
53 end)
54
55 assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
56 end
57
58 test "it downloads and unzips unknown frontends" do
59 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
60 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
61 end)
62
63 capture_io(fn ->
64 Frontend.run([
65 "install",
66 "unknown",
67 "--ref",
68 "baka",
69 "--build-url",
70 "http://gensokyo.2hu/madeup.zip",
71 "--build-dir",
72 ""
73 ])
74 end)
75
76 assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
77 end
78 end