tests: add legal boilerplate
[akkoma] / test / plugs / instance_static_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 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 static_dir = Pleroma.Config.get([:instance, :static_dir])
12 Pleroma.Config.put([:instance, :static_dir], @dir)
13 File.mkdir_p!(@dir)
14
15 on_exit(fn ->
16 Pleroma.Config.put([:instance, :static_dir], static_dir)
17 File.rm_rf(@dir)
18 end)
19 end
20
21 test "overrides index" do
22 bundled_index = get(build_conn(), "/")
23 assert html_response(bundled_index, 200) == File.read!("priv/static/index.html")
24
25 File.write!(@dir <> "/index.html", "hello world")
26
27 index = get(build_conn(), "/")
28 assert html_response(index, 200) == "hello world"
29 end
30
31 test "overrides any file in static/static" do
32 bundled_index = get(build_conn(), "/static/terms-of-service.html")
33
34 assert html_response(bundled_index, 200) ==
35 File.read!("priv/static/static/terms-of-service.html")
36
37 File.mkdir!(@dir <> "/static")
38 File.write!(@dir <> "/static/terms-of-service.html", "plz be kind")
39
40 index = get(build_conn(), "/static/terms-of-service.html")
41 assert html_response(index, 200) == "plz be kind"
42
43 File.write!(@dir <> "/static/kaniini.html", "<h1>rabbit hugs as a service</h1>")
44 index = get(build_conn(), "/static/kaniini.html")
45 assert html_response(index, 200) == "<h1>rabbit hugs as a service</h1>"
46 end
47 end