1 defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
2 use Pleroma.Web.ConnCase
6 alias Pleroma.Web.ActivityPub.Transmogrifier
7 alias Pleroma.Web.CommonAPI
11 clear_config_all([:static_fe, :enabled]) do
12 Config.put([:static_fe, :enabled], true)
15 setup %{conn: conn} do
16 conn = put_req_header(conn, "accept", "text/html")
19 %{conn: conn, user: user}
22 describe "user profile html" do
23 test "just the profile as HTML", %{conn: conn, user: user} do
24 conn = get(conn, "/users/#{user.nickname}")
26 assert html_response(conn, 200) =~ user.nickname
29 test "404 when user not found", %{conn: conn} do
30 conn = get(conn, "/users/limpopo")
32 assert html_response(conn, 404) =~ "not found"
35 test "profile does not include private messages", %{conn: conn, user: user} do
36 CommonAPI.post(user, %{"status" => "public"})
37 CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
39 conn = get(conn, "/users/#{user.nickname}")
41 html = html_response(conn, 200)
43 assert html =~ ">public<"
44 refute html =~ ">private<"
47 test "pagination", %{conn: conn, user: user} do
48 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
50 conn = get(conn, "/users/#{user.nickname}")
52 html = html_response(conn, 200)
54 assert html =~ ">test30<"
55 assert html =~ ">test11<"
56 refute html =~ ">test10<"
57 refute html =~ ">test1<"
60 test "pagination, page 2", %{conn: conn, user: user} do
61 activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
62 {:ok, a11} = Enum.at(activities, 11)
64 conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
66 html = html_response(conn, 200)
68 assert html =~ ">test1<"
69 assert html =~ ">test10<"
70 refute html =~ ">test20<"
71 refute html =~ ">test29<"
75 describe "notice html" do
76 test "single notice page", %{conn: conn, user: user} do
77 {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
79 conn = get(conn, "/notice/#{activity.id}")
81 html = html_response(conn, 200)
82 assert html =~ "<header>"
83 assert html =~ user.nickname
84 assert html =~ "testing a thing!"
87 test "shows the whole thread", %{conn: conn, user: user} do
88 {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
90 CommonAPI.post(user, %{
91 "status" => "these are the voyages or something",
92 "in_reply_to_status_id" => activity.id
95 conn = get(conn, "/notice/#{activity.id}")
97 html = html_response(conn, 200)
98 assert html =~ "the final frontier"
99 assert html =~ "voyages"
102 test "redirect by AP object ID", %{conn: conn, user: user} do
103 {:ok, %Activity{data: %{"object" => object_url}}} =
104 CommonAPI.post(user, %{"status" => "beam me up"})
106 conn = get(conn, URI.parse(object_url).path)
108 assert html_response(conn, 302) =~ "redirected"
111 test "redirect by activity ID", %{conn: conn, user: user} do
112 {:ok, %Activity{data: %{"id" => id}}} =
113 CommonAPI.post(user, %{"status" => "I'm a doctor, not a devops!"})
115 conn = get(conn, URI.parse(id).path)
117 assert html_response(conn, 302) =~ "redirected"
120 test "404 when notice not found", %{conn: conn} do
121 conn = get(conn, "/notice/88c9c317")
123 assert html_response(conn, 404) =~ "not found"
126 test "404 for private status", %{conn: conn, user: user} do
128 CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
130 conn = get(conn, "/notice/#{activity.id}")
132 assert html_response(conn, 404) =~ "not found"
135 test "302 for remote cached status", %{conn: conn, user: user} do
137 "@context" => "https://www.w3.org/ns/activitystreams",
138 "to" => user.follower_address,
139 "cc" => "https://www.w3.org/ns/activitystreams#Public",
142 "content" => "blah blah blah",
144 "attributedTo" => user.ap_id,
147 "actor" => user.ap_id
150 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
152 conn = get(conn, "/notice/#{activity.id}")
154 assert html_response(conn, 302) =~ "redirected"