logo

pleroma

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

error_view_test.exs (1366B)


  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.ErrorViewTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. import ExUnit.CaptureLog
  7. # Bring render/3 and render_to_string/3 for testing custom views
  8. import Phoenix.View
  9. test "renders 404.json" do
  10. assert render(Pleroma.Web.ErrorView, "404.json", []) == %{errors: %{detail: "Page not found"}}
  11. end
  12. test "render 500.json" do
  13. assert capture_log(fn ->
  14. assert render(Pleroma.Web.ErrorView, "500.json", []) ==
  15. %{errors: %{detail: "Internal server error", reason: "nil"}}
  16. end) =~ "[error] Internal server error: nil"
  17. end
  18. test "render any other" do
  19. assert capture_log(fn ->
  20. assert render(Pleroma.Web.ErrorView, "505.json", []) ==
  21. %{errors: %{detail: "Internal server error", reason: "nil"}}
  22. end) =~ "[error] Internal server error: nil"
  23. end
  24. test "render 500.json with reason" do
  25. assert capture_log(fn ->
  26. assert render(Pleroma.Web.ErrorView, "500.json", reason: "test reason") ==
  27. %{errors: %{detail: "Internal server error", reason: "\"test reason\""}}
  28. end) =~ "[error] Internal server error: \"test reason\""
  29. end
  30. end