6a9a931eb5d36889a13c4507c1e13e3ee87603de
[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 "build_dir" => ""
29 }
30 })
31
32 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
33 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
34 end)
35
36 capture_io(fn ->
37 Frontend.run(["install", "pleroma"])
38 end)
39
40 assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
41 end
42
43 test "it also works given a file" do
44 clear_config([:frontends, :available], %{
45 "pleroma" => %{
46 "ref" => "fantasy",
47 "name" => "pleroma",
48 "build_dir" => ""
49 }
50 })
51
52 capture_io(fn ->
53 Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
54 end)
55
56 assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
57 end
58
59 test "it downloads and unzips unknown frontends" do
60 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
61 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
62 end)
63
64 capture_io(fn ->
65 Frontend.run([
66 "install",
67 "unknown",
68 "--ref",
69 "baka",
70 "--build-url",
71 "http://gensokyo.2hu/madeup.zip",
72 "--build-dir",
73 ""
74 ])
75 end)
76
77 assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
78 end
79 end