526679aae2addda2b6fc4624652e51a4bd0379c9
[akkoma] / test / plugs / instance_static_test.exs
1 defmodule Pleroma.Web.RuntimeStaticPlugTest do
2 use Pleroma.Web.ConnCase
3
4 @dir "test/tmp/instance_static"
5
6 setup do
7 static_dir = Pleroma.Config.get([:instance, :static_dir])
8 Pleroma.Config.put([:instance, :static_dir], @dir)
9 File.mkdir_p!(@dir)
10
11 on_exit(fn ->
12 Pleroma.Config.put([:instance, :static_dir], static_dir)
13 File.rm_rf(@dir)
14 end)
15 end
16
17 test "overrides index" do
18 bundled_index = get(build_conn(), "/")
19 assert html_response(bundled_index, 200) == File.read!("priv/static/index.html")
20
21 File.write!(@dir <> "/index.html", "hello world")
22
23 index = get(build_conn(), "/")
24 assert html_response(index, 200) == "hello world"
25 end
26
27 test "overrides any file in static/static" do
28 bundled_index = get(build_conn(), "/static/terms-of-service.html")
29
30 assert html_response(bundled_index, 200) ==
31 File.read!("priv/static/static/terms-of-service.html")
32
33 File.mkdir!(@dir <> "/static")
34 File.write!(@dir <> "/static/terms-of-service.html", "plz be kind")
35
36 index = get(build_conn(), "/static/terms-of-service.html")
37 assert html_response(index, 200) == "plz be kind"
38
39 File.write!(@dir <> "/static/kaniini.html", "<h1>rabbit hugs as a service</h1>")
40 index = get(build_conn(), "/static/kaniini.html")
41 assert html_response(index, 200) == "<h1>rabbit hugs as a service</h1>"
42 end
43 end