1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
6 use Pleroma.Web.ConnCase
8 @dir "test/tmp/instance_static"
12 on_exit(fn -> File.rm_rf(@dir) end)
15 setup do: clear_config([:instance, :static_dir], @dir)
17 test "init will give a static plug config + the frontend type" do
23 |> Pleroma.Web.Plugs.FrontendStatic.init()
25 assert opts[:at] == ["admin"]
26 assert opts[:frontend_type] == :admin
29 test "overrides existing static files", %{conn: conn} do
33 clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
34 path = "#{@dir}/frontends/#{name}/#{ref}"
37 File.write!("#{path}/index.html", "from frontend plug")
39 index = get(conn, "/")
40 assert html_response(index, 200) == "from frontend plug"
43 test "overrides existing static files for the `pleroma/admin` path", %{conn: conn} do
47 clear_config([:frontends, :admin], %{"name" => name, "ref" => ref})
48 path = "#{@dir}/frontends/#{name}/#{ref}"
51 File.write!("#{path}/index.html", "from frontend plug")
53 index = get(conn, "/pleroma/admin/")
54 assert html_response(index, 200) == "from frontend plug"