Introduce support for custom nginx error pages

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-10-09 12:17:33 +02:00
parent 3a3a500e42
commit 07a5d10421
31 changed files with 476 additions and 63 deletions

View File

@@ -0,0 +1,31 @@
defmodule Mobilizon.Service.ErrorPageTest do
@moduledoc """
Test the error page producer module
"""
alias Mobilizon.Config
alias Mobilizon.Service.ErrorPage
use Mobilizon.DataCase
describe "init/0" do
test "renders an error page in the default language" do
ErrorPage.init()
path = Path.join(Application.app_dir(:mobilizon, "priv/errors"), "error.html")
assert File.exists?(path)
assert {:ok, data} = File.read(path)
assert data =~ "This page is not correct"
end
test "uses the instance default language if defined" do
Config.put([:instance, :default_language], "fr")
ErrorPage.init()
path = Path.join(Application.app_dir(:mobilizon, "priv/errors"), "error.html")
assert File.exists?(path)
assert {:ok, data} = File.read(path)
refute data =~ "This page is not correct"
assert data =~ "<html lang=\"fr\">"
Config.put([:instance, :default_language], "en")
end
end
end

View File

@@ -17,10 +17,14 @@ defmodule Mobilizon.Web.ErrorViewTest do
end
test "render 500.html" do
assert render_to_string(ErrorView, "500.html", []) == "Internal server error"
assert render_to_string(ErrorView, "500.html", []) =~
Phoenix.HTML.html_escape("We're sorry, but something went wrong on our end.")
|> Phoenix.HTML.safe_to_string()
end
test "render any other" do
assert render_to_string(ErrorView, "505.html", []) == "Internal server error"
assert render_to_string(ErrorView, "505.html", []) =~
Phoenix.HTML.html_escape("We're sorry, but something went wrong on our end.")
|> Phoenix.HTML.safe_to_string()
end
end