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