Merge branch 'feature/static-fe' into 'develop'
[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.ActivityPub.Transmogrifier
4 alias Pleroma.Web.CommonAPI
5
6 import Pleroma.Factory
7
8 clear_config_all([:static_fe, :enabled]) do
9 Pleroma.Config.put([:static_fe, :enabled], true)
10 end
11
12 describe "user profile page" do
13 test "just the profile as HTML", %{conn: conn} do
14 user = insert(:user)
15
16 conn =
17 conn
18 |> put_req_header("accept", "text/html")
19 |> get("/users/#{user.nickname}")
20
21 assert html_response(conn, 200) =~ user.nickname
22 end
23
24 test "renders json unless there's an html accept header", %{conn: conn} do
25 user = insert(:user)
26
27 conn =
28 conn
29 |> put_req_header("accept", "application/json")
30 |> get("/users/#{user.nickname}")
31
32 assert json_response(conn, 200)
33 end
34
35 test "404 when user not found", %{conn: conn} do
36 conn =
37 conn
38 |> put_req_header("accept", "text/html")
39 |> get("/users/limpopo")
40
41 assert html_response(conn, 404) =~ "not found"
42 end
43
44 test "profile does not include private messages", %{conn: conn} do
45 user = insert(:user)
46 CommonAPI.post(user, %{"status" => "public"})
47 CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
48
49 conn =
50 conn
51 |> put_req_header("accept", "text/html")
52 |> get("/users/#{user.nickname}")
53
54 html = html_response(conn, 200)
55
56 assert html =~ ">public<"
57 refute html =~ ">private<"
58 end
59
60 test "pagination", %{conn: conn} do
61 user = insert(:user)
62 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
63
64 conn =
65 conn
66 |> put_req_header("accept", "text/html")
67 |> get("/users/#{user.nickname}")
68
69 html = html_response(conn, 200)
70
71 assert html =~ ">test30<"
72 assert html =~ ">test11<"
73 refute html =~ ">test10<"
74 refute html =~ ">test1<"
75 end
76
77 test "pagination, page 2", %{conn: conn} do
78 user = insert(:user)
79 activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
80 {:ok, a11} = Enum.at(activities, 11)
81
82 conn =
83 conn
84 |> put_req_header("accept", "text/html")
85 |> get("/users/#{user.nickname}?max_id=#{a11.id}")
86
87 html = html_response(conn, 200)
88
89 assert html =~ ">test1<"
90 assert html =~ ">test10<"
91 refute html =~ ">test20<"
92 refute html =~ ">test29<"
93 end
94 end
95
96 describe "notice rendering" do
97 test "single notice page", %{conn: conn} do
98 user = insert(:user)
99 {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
100
101 conn =
102 conn
103 |> put_req_header("accept", "text/html")
104 |> get("/notice/#{activity.id}")
105
106 html = html_response(conn, 200)
107 assert html =~ "<header>"
108 assert html =~ user.nickname
109 assert html =~ "testing a thing!"
110 end
111
112 test "shows the whole thread", %{conn: conn} do
113 user = insert(:user)
114 {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
115
116 CommonAPI.post(user, %{
117 "status" => "these are the voyages or something",
118 "in_reply_to_status_id" => activity.id
119 })
120
121 conn =
122 conn
123 |> put_req_header("accept", "text/html")
124 |> get("/notice/#{activity.id}")
125
126 html = html_response(conn, 200)
127 assert html =~ "the final frontier"
128 assert html =~ "voyages"
129 end
130
131 test "404 when notice not found", %{conn: conn} do
132 conn =
133 conn
134 |> put_req_header("accept", "text/html")
135 |> get("/notice/88c9c317")
136
137 assert html_response(conn, 404) =~ "not found"
138 end
139
140 test "404 for private status", %{conn: conn} do
141 user = insert(:user)
142
143 {:ok, activity} =
144 CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
145
146 conn =
147 conn
148 |> put_req_header("accept", "text/html")
149 |> get("/notice/#{activity.id}")
150
151 assert html_response(conn, 404) =~ "not found"
152 end
153
154 test "404 for remote cached status", %{conn: conn} do
155 user = insert(:user)
156
157 message = %{
158 "@context" => "https://www.w3.org/ns/activitystreams",
159 "to" => user.follower_address,
160 "cc" => "https://www.w3.org/ns/activitystreams#Public",
161 "type" => "Create",
162 "object" => %{
163 "content" => "blah blah blah",
164 "type" => "Note",
165 "attributedTo" => user.ap_id,
166 "inReplyTo" => nil
167 },
168 "actor" => user.ap_id
169 }
170
171 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
172
173 conn =
174 conn
175 |> put_req_header("accept", "text/html")
176 |> get("/notice/#{activity.id}")
177
178 assert html_response(conn, 404) =~ "not found"
179 end
180 end
181 end