Merge branch 'develop' into refactor/discoverable_user_field
[akkoma] / test / pleroma / web / plugs / frontend_static_plug_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.Web.Plugs.FrontendStaticPlugTest do
6 use Pleroma.Web.ConnCase
7
8 @dir "test/tmp/instance_static"
9
10 setup do
11 File.mkdir_p!(@dir)
12 on_exit(fn -> File.rm_rf(@dir) end)
13 end
14
15 setup do: clear_config([:instance, :static_dir], @dir)
16
17 test "init will give a static plug config + the frontend type" do
18 opts =
19 [
20 at: "/admin",
21 frontend_type: :admin
22 ]
23 |> Pleroma.Web.Plugs.FrontendStatic.init()
24
25 assert opts[:at] == ["admin"]
26 assert opts[:frontend_type] == :admin
27 end
28
29 test "overrides existing static files", %{conn: conn} do
30 name = "pelmora"
31 ref = "uguu"
32
33 clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
34 path = "#{@dir}/frontends/#{name}/#{ref}"
35
36 File.mkdir_p!(path)
37 File.write!("#{path}/index.html", "from frontend plug")
38
39 index = get(conn, "/")
40 assert html_response(index, 200) == "from frontend plug"
41 end
42
43 test "overrides existing static files for the `pleroma/admin` path", %{conn: conn} do
44 name = "pelmora"
45 ref = "uguu"
46
47 clear_config([:frontends, :admin], %{"name" => name, "ref" => ref})
48 path = "#{@dir}/frontends/#{name}/#{ref}"
49
50 File.mkdir_p!(path)
51 File.write!("#{path}/index.html", "from frontend plug")
52
53 index = get(conn, "/pleroma/admin/")
54 assert html_response(index, 200) == "from frontend plug"
55 end
56 end