1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.InstanceStaticTest 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 "overrides index" do
18 bundled_index = get(build_conn(), "/")
19 refute html_response(bundled_index, 200) == "hello world"
21 File.write!(@dir <> "/index.html", "hello world")
23 index = get(build_conn(), "/")
24 assert html_response(index, 200) == "hello world"
27 test "also overrides frontend files", %{conn: conn} do
31 clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
33 bundled_index = get(conn, "/")
34 refute html_response(bundled_index, 200) == "from frontend plug"
36 path = "#{@dir}/frontends/#{name}/#{ref}"
38 File.write!("#{path}/index.html", "from frontend plug")
40 index = get(conn, "/")
41 assert html_response(index, 200) == "from frontend plug"
43 File.write!(@dir <> "/index.html", "from instance static")
45 index = get(conn, "/")
46 assert html_response(index, 200) == "from instance static"