logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

fallback_test.exs (2861B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.FallbackTest do
  5. use Pleroma.Web.ConnCase
  6. import Pleroma.Factory
  7. test "GET /*path adds a title", %{conn: conn} do
  8. clear_config([:instance, :name], "a cool title")
  9. assert conn
  10. |> get("/")
  11. |> html_response(200) =~ "<title>a cool title</title>"
  12. end
  13. describe "preloaded data and metadata attached to" do
  14. test "GET /:maybe_nickname_or_id with existing user", %{conn: conn} do
  15. clear_config([:instance, :name], "a cool title")
  16. user = insert(:user)
  17. resp = get(conn, "/#{user.nickname}")
  18. assert html_response(resp, 200) =~ "<title>a cool title</title>"
  19. refute html_response(resp, 200) =~ "<!--server-generated-meta-->"
  20. assert html_response(resp, 200) =~ "initial-results"
  21. end
  22. test "GET /:maybe_nickname_or_id with missing user", %{conn: conn} do
  23. clear_config([:instance, :name], "a cool title")
  24. resp = get(conn, "/foo")
  25. assert html_response(resp, 200) =~ "<title>a cool title</title>"
  26. refute html_response(resp, 200) =~ "initial-results"
  27. end
  28. test "GET /*path", %{conn: conn} do
  29. refute conn
  30. |> get("/foo")
  31. |> html_response(200) =~ "<!--server-generated-meta-->"
  32. refute conn
  33. |> get("/foo/bar")
  34. |> html_response(200) =~ "<!--server-generated-meta-->"
  35. end
  36. end
  37. describe "preloaded data is attached to" do
  38. test "GET /main/public", %{conn: conn} do
  39. clear_config([:instance, :name], "a cool title")
  40. public_page = get(conn, "/main/public")
  41. refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
  42. assert html_response(public_page, 200) =~ "initial-results"
  43. assert html_response(public_page, 200) =~ "<title>a cool title</title>"
  44. end
  45. test "GET /main/all", %{conn: conn} do
  46. clear_config([:instance, :name], "a cool title")
  47. public_page = get(conn, "/main/all")
  48. refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
  49. assert html_response(public_page, 200) =~ "initial-results"
  50. assert html_response(public_page, 200) =~ "<title>a cool title</title>"
  51. end
  52. end
  53. test "GET /api*path", %{conn: conn} do
  54. assert conn
  55. |> get("/api/foo")
  56. |> json_response(404) == %{"error" => "Not implemented"}
  57. end
  58. test "GET /pleroma/admin -> /pleroma/admin/", %{conn: conn} do
  59. assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/"
  60. end
  61. test "OPTIONS /*path", %{conn: conn} do
  62. assert conn
  63. |> options("/foo")
  64. |> response(204) == ""
  65. assert conn
  66. |> options("/foo/bar")
  67. |> response(204) == ""
  68. end
  69. end