Merge pull request 'purge scrobbling' (#90) from purge/scrobbling into develop
[akkoma] / test / pleroma / web / fallback_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.FallbackTest do
6 use Pleroma.Web.ConnCase
7 import Pleroma.Factory
8
9 describe "neither preloaded data nor metadata attached to" do
10 test "GET /registration/:token", %{conn: conn} do
11 response = get(conn, "/registration/foo")
12
13 assert html_response(response, 200) =~ "<!--server-generated-meta-->"
14 end
15
16 test "GET /*path", %{conn: conn} do
17 assert conn
18 |> get("/foo")
19 |> html_response(200) =~ "<!--server-generated-meta-->"
20 end
21 end
22
23 test "GET /*path adds a title", %{conn: conn} do
24 clear_config([:instance, :name], "a cool title")
25
26 assert conn
27 |> get("/")
28 |> html_response(200) =~ "<title>a cool title</title>"
29 end
30
31 describe "preloaded data and metadata attached to" do
32 test "GET /:maybe_nickname_or_id", %{conn: conn} do
33 clear_config([:instance, :name], "a cool title")
34
35 user = insert(:user)
36 user_missing = get(conn, "/foo")
37 user_present = get(conn, "/#{user.nickname}")
38
39 assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
40 refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
41 assert html_response(user_present, 200) =~ "initial-results"
42 assert html_response(user_present, 200) =~ "<title>a cool title</title>"
43 end
44
45 test "GET /*path", %{conn: conn} do
46 assert conn
47 |> get("/foo")
48 |> html_response(200) =~ "<!--server-generated-meta-->"
49
50 refute conn
51 |> get("/foo/bar")
52 |> html_response(200) =~ "<!--server-generated-meta-->"
53 end
54 end
55
56 describe "preloaded data is attached to" do
57 test "GET /main/public", %{conn: conn} do
58 clear_config([:instance, :name], "a cool title")
59
60 public_page = get(conn, "/main/public")
61
62 refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
63 assert html_response(public_page, 200) =~ "initial-results"
64 assert html_response(public_page, 200) =~ "<title>a cool title</title>"
65 end
66
67 test "GET /main/all", %{conn: conn} do
68 public_page = get(conn, "/main/all")
69
70 refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
71 assert html_response(public_page, 200) =~ "initial-results"
72 end
73 end
74
75 test "GET /api*path", %{conn: conn} do
76 assert conn
77 |> get("/api/foo")
78 |> json_response(404) == %{"error" => "Not implemented"}
79 end
80
81 test "GET /pleroma/admin -> /pleroma/admin/", %{conn: conn} do
82 assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/"
83 end
84
85 test "OPTIONS /*path", %{conn: conn} do
86 assert conn
87 |> options("/foo")
88 |> response(204) == ""
89
90 assert conn
91 |> options("/foo/bar")
92 |> response(204) == ""
93 end
94 end