Change user.discoverable field to user.is_discoverable
[akkoma] / test / mix / tasks / pleroma / 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 Mix.Tasks.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 folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
52 previously_existing = Path.join([folder, "temp"])
53 File.mkdir_p!(folder)
54 File.write!(previously_existing, "yey")
55 assert File.exists?(previously_existing)
56
57 capture_io(fn ->
58 Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
59 end)
60
61 assert File.exists?(Path.join([folder, "test.txt"]))
62 refute File.exists?(previously_existing)
63 end
64
65 test "it downloads and unzips unknown frontends" do
66 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
67 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
68 end)
69
70 capture_io(fn ->
71 Frontend.run([
72 "install",
73 "unknown",
74 "--ref",
75 "baka",
76 "--build-url",
77 "http://gensokyo.2hu/madeup.zip",
78 "--build-dir",
79 ""
80 ])
81 end)
82
83 assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
84 end
85 end