1 defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.Web.ActivityPub.Transmogrifier
5 alias Pleroma.Web.CommonAPI
9 clear_config_all([:static_fe, :enabled]) do
10 Pleroma.Config.put([:static_fe, :enabled], true)
13 describe "user profile page" do
14 test "just the profile as HTML", %{conn: conn} do
19 |> put_req_header("accept", "text/html")
20 |> get("/users/#{user.nickname}")
22 assert html_response(conn, 200) =~ user.nickname
25 test "renders json unless there's an html accept header", %{conn: conn} do
30 |> put_req_header("accept", "application/json")
31 |> get("/users/#{user.nickname}")
33 assert json_response(conn, 200)
36 test "404 when user not found", %{conn: conn} do
39 |> put_req_header("accept", "text/html")
40 |> get("/users/limpopo")
42 assert html_response(conn, 404) =~ "not found"
45 test "profile does not include private messages", %{conn: conn} do
47 CommonAPI.post(user, %{"status" => "public"})
48 CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
52 |> put_req_header("accept", "text/html")
53 |> get("/users/#{user.nickname}")
55 html = html_response(conn, 200)
57 assert html =~ ">public<"
58 refute html =~ ">private<"
61 test "pagination", %{conn: conn} do
63 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
67 |> put_req_header("accept", "text/html")
68 |> get("/users/#{user.nickname}")
70 html = html_response(conn, 200)
72 assert html =~ ">test30<"
73 assert html =~ ">test11<"
74 refute html =~ ">test10<"
75 refute html =~ ">test1<"
78 test "pagination, page 2", %{conn: conn} do
80 activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
81 {:ok, a11} = Enum.at(activities, 11)
85 |> put_req_header("accept", "text/html")
86 |> get("/users/#{user.nickname}?max_id=#{a11.id}")
88 html = html_response(conn, 200)
90 assert html =~ ">test1<"
91 assert html =~ ">test10<"
92 refute html =~ ">test20<"
93 refute html =~ ">test29<"
97 describe "notice rendering" do
98 test "single notice page", %{conn: conn} do
100 {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
104 |> put_req_header("accept", "text/html")
105 |> get("/notice/#{activity.id}")
107 html = html_response(conn, 200)
108 assert html =~ "<header>"
109 assert html =~ user.nickname
110 assert html =~ "testing a thing!"
113 test "shows the whole thread", %{conn: conn} do
115 {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
117 CommonAPI.post(user, %{
118 "status" => "these are the voyages or something",
119 "in_reply_to_status_id" => activity.id
124 |> put_req_header("accept", "text/html")
125 |> get("/notice/#{activity.id}")
127 html = html_response(conn, 200)
128 assert html =~ "the final frontier"
129 assert html =~ "voyages"
132 test "redirect by AP object ID", %{conn: conn} do
135 {:ok, %Activity{data: %{"object" => object_url}}} =
136 CommonAPI.post(user, %{"status" => "beam me up"})
140 |> put_req_header("accept", "text/html")
141 |> get(URI.parse(object_url).path)
143 assert html_response(conn, 302) =~ "redirected"
146 test "redirect by activity ID", %{conn: conn} do
149 {:ok, %Activity{data: %{"id" => id}}} =
150 CommonAPI.post(user, %{"status" => "I'm a doctor, not a devops!"})
154 |> put_req_header("accept", "text/html")
155 |> get(URI.parse(id).path)
157 assert html_response(conn, 302) =~ "redirected"
160 test "404 when notice not found", %{conn: conn} do
163 |> put_req_header("accept", "text/html")
164 |> get("/notice/88c9c317")
166 assert html_response(conn, 404) =~ "not found"
169 test "404 for private status", %{conn: conn} do
173 CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
177 |> put_req_header("accept", "text/html")
178 |> get("/notice/#{activity.id}")
180 assert html_response(conn, 404) =~ "not found"
183 test "302 for remote cached status", %{conn: conn} do
187 "@context" => "https://www.w3.org/ns/activitystreams",
188 "to" => user.follower_address,
189 "cc" => "https://www.w3.org/ns/activitystreams#Public",
192 "content" => "blah blah blah",
194 "attributedTo" => user.ap_id,
197 "actor" => user.ap_id
200 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
204 |> put_req_header("accept", "text/html")
205 |> get("/notice/#{activity.id}")
207 assert html_response(conn, 302) =~ "redirected"