Resolve follow activity from accept/reject without ID (#328)
[akkoma] / test / pleroma / frontend_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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 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 }
27 })
28
29 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
30 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
31 end)
32
33 Frontend.install("pleroma")
34
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 folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
48 previously_existing = Path.join([folder, "temp"])
49 File.mkdir_p!(folder)
50 File.write!(previously_existing, "yey")
51 assert File.exists?(previously_existing)
52
53 Frontend.install("pleroma", file: "test/fixtures/tesla_mock/frontend.zip")
54
55 assert File.exists?(Path.join([folder, "test.txt"]))
56 refute File.exists?(previously_existing)
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 Frontend.install("unknown",
65 ref: "baka",
66 build_url: "http://gensokyo.2hu/madeup.zip",
67 build_dir: ""
68 )
69
70 assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
71 end
72 end