logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

frontend_static_test.exs (1551B)


  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. defmodule Pleroma.Web.FrontendStaticPlugTest do
  5. alias Pleroma.Plugs.FrontendStatic
  6. use Pleroma.Web.ConnCase
  7. @dir "test/tmp/instance_static"
  8. setup do
  9. File.mkdir_p!(@dir)
  10. on_exit(fn -> File.rm_rf(@dir) end)
  11. end
  12. setup do: clear_config([:instance, :static_dir], @dir)
  13. test "init will give a static plug config + the frontend type" do
  14. opts =
  15. [
  16. at: "/admin",
  17. frontend_type: :admin
  18. ]
  19. |> FrontendStatic.init()
  20. assert opts[:at] == ["admin"]
  21. assert opts[:frontend_type] == :admin
  22. end
  23. test "overrides existing static files", %{conn: conn} do
  24. name = "pelmora"
  25. ref = "uguu"
  26. clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
  27. path = "#{@dir}/frontends/#{name}/#{ref}"
  28. File.mkdir_p!(path)
  29. File.write!("#{path}/index.html", "from frontend plug")
  30. index = get(conn, "/")
  31. assert html_response(index, 200) == "from frontend plug"
  32. end
  33. test "overrides existing static files for the `pleroma/admin` path", %{conn: conn} do
  34. name = "pelmora"
  35. ref = "uguu"
  36. clear_config([:frontends, :admin], %{"name" => name, "ref" => ref})
  37. path = "#{@dir}/frontends/#{name}/#{ref}"
  38. File.mkdir_p!(path)
  39. File.write!("#{path}/index.html", "from frontend plug")
  40. index = get(conn, "/pleroma/admin/")
  41. assert html_response(index, 200) == "from frontend plug"
  42. end
  43. end