Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / plugs / instance_static_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.RuntimeStaticPlugTest 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 clear_config([:instance, :static_dir]) do
16 Pleroma.Config.put([:instance, :static_dir], @dir)
17 end
18
19 test "overrides index" do
20 bundled_index = get(build_conn(), "/")
21 assert html_response(bundled_index, 200) == File.read!("priv/static/index.html")
22
23 File.write!(@dir <> "/index.html", "hello world")
24
25 index = get(build_conn(), "/")
26 assert html_response(index, 200) == "hello world"
27 end
28
29 test "overrides any file in static/static" do
30 bundled_index = get(build_conn(), "/static/terms-of-service.html")
31
32 assert html_response(bundled_index, 200) ==
33 File.read!("priv/static/static/terms-of-service.html")
34
35 File.mkdir!(@dir <> "/static")
36 File.write!(@dir <> "/static/terms-of-service.html", "plz be kind")
37
38 index = get(build_conn(), "/static/terms-of-service.html")
39 assert html_response(index, 200) == "plz be kind"
40
41 File.write!(@dir <> "/static/kaniini.html", "<h1>rabbit hugs as a service</h1>")
42 index = get(build_conn(), "/static/kaniini.html")
43 assert html_response(index, 200) == "<h1>rabbit hugs as a service</h1>"
44 end
45 end