Add tests for static_fe controller.
[akkoma] / test / web / static_fe / static_fe_controller_test.exs
1 defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
2 use Pleroma.Web.ConnCase
3 alias Pleroma.Web.CommonAPI
4 import Pleroma.Factory
5
6 clear_config_all([:static_fe, :enabled]) do
7 Pleroma.Config.put([:static_fe, :enabled], true)
8 end
9
10 describe "user profile page" do
11 test "just the profile as HTML", %{conn: conn} do
12 user = insert(:user)
13 conn = conn
14 |> put_req_header("accept", "text/html")
15 |> get("/users/#{user.nickname}")
16
17 assert html_response(conn, 200) =~ user.nickname
18 end
19
20 test "renders json unless there's an html accept header", %{conn: conn} do
21 user = insert(:user)
22 conn = conn
23 |> put_req_header("accept", "application/json")
24 |> get("/users/#{user.nickname}")
25
26 assert json_response(conn, 200)
27 end
28
29 test "404 when user not found", %{conn: conn} do
30 conn = conn
31 |> put_req_header("accept", "text/html")
32 |> get("/users/limpopo")
33
34 assert html_response(conn, 404) =~ "not found"
35 end
36
37 test "pagination", %{conn: conn} do
38 user = insert(:user)
39 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
40 conn = conn
41 |> put_req_header("accept", "text/html")
42 |> get("/users/#{user.nickname}")
43 html = html_response(conn, 200)
44
45 assert html =~ ">test30<"
46 assert html =~ ">test11<"
47 refute html =~ ">test10<"
48 refute html =~ ">test1<"
49 end
50
51 test "pagination, page 2", %{conn: conn} do
52 user = insert(:user)
53 activities =
54 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
55 {:ok, a11} = Enum.at(activities, 11)
56 conn = conn
57 |> put_req_header("accept", "text/html")
58 |> get("/users/#{user.nickname}?max_id=#{a11.id}")
59 html = html_response(conn, 200)
60
61 assert html =~ ">test1<"
62 assert html =~ ">test10<"
63 refute html =~ ">test20<"
64 refute html =~ ">test29<"
65 end
66 end
67
68 describe "notice rendering" do
69 test "single notice page", %{conn: conn} do
70 user = insert(:user)
71 {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
72
73 conn = conn
74 |> put_req_header("accept", "text/html")
75 |> get("/notice/#{activity.id}")
76
77 html = html_response(conn, 200)
78 assert html =~ "<header>"
79 assert html =~ user.nickname
80 assert html =~ "testing a thing!"
81 end
82
83 test "404 when notice not found", %{conn: conn} do
84 conn = conn
85 |> put_req_header("accept", "text/html")
86 |> get("/notice/88c9c317")
87
88 assert html_response(conn, 404) =~ "not found"
89 end
90 end
91 end