1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ErrorViewTest do
6 use Pleroma.Web.ConnCase, async: true
7 import ExUnit.CaptureLog
9 # Bring render/3 and render_to_string/3 for testing custom views
12 test "renders 404.json" do
13 assert render(Pleroma.Web.ErrorView, "404.json", []) == %{errors: %{detail: "Page not found"}}
16 test "render 500.json" do
17 assert capture_log(fn ->
18 assert render(Pleroma.Web.ErrorView, "500.json", []) ==
19 %{errors: %{detail: "Internal server error", reason: "nil"}}
20 end) =~ "[error] Internal server error: nil"
23 test "render any other" do
24 assert capture_log(fn ->
25 assert render(Pleroma.Web.ErrorView, "505.json", []) ==
26 %{errors: %{detail: "Internal server error", reason: "nil"}}
27 end) =~ "[error] Internal server error: nil"
30 test "render 500.json with reason" do
31 assert capture_log(fn ->
32 assert render(Pleroma.Web.ErrorView, "500.json", reason: "test reason") ==
33 %{errors: %{detail: "Internal server error", reason: "\"test reason\""}}
34 end) =~ "[error] Internal server error: \"test reason\""