5cd4594e2aea66a152fbc154d557eeb290242f03
[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 @dir "test/frontend_static_test"
10
11 setup do
12 File.mkdir_p!(@dir)
13 clear_config([:instance, :static_dir], @dir)
14
15 on_exit(fn ->
16 File.rm_rf(@dir)
17 end)
18 end
19
20 test "it downloads and unzips a known frontend" do
21 clear_config([:frontends, :available], %{
22 "pleroma" => %{
23 "ref" => "fantasy",
24 "name" => "pleroma",
25 "build_url" => "http://gensokyo.2hu/builds/${ref}",
26 "build_dir" => ""
27 }
28 })
29
30 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
31 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
32 end)
33
34 Frontend.run(["install", "pleroma"])
35 assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
36 end
37
38 test "it also works given a file" do
39 clear_config([:frontends, :available], %{
40 "pleroma" => %{
41 "ref" => "fantasy",
42 "name" => "pleroma",
43 "build_dir" => ""
44 }
45 })
46
47 Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
48 assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
49 end
50
51 test "it downloads and unzips unknown frontends" do
52 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
53 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
54 end)
55
56 Frontend.run([
57 "install",
58 "unknown",
59 "--ref",
60 "baka",
61 "--build-url",
62 "http://gensokyo.2hu/madeup.zip",
63 "--build-dir",
64 ""
65 ])
66
67 assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
68 end
69 end