Merge remote-tracking branch 'remotes/origin/develop' into 1560-non-federating-instan...
[akkoma] / test / web / static_fe / static_fe_controller_test.exs
1 defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
2 use Pleroma.Web.ConnCase
3
4 alias Pleroma.Activity
5 alias Pleroma.Config
6 alias Pleroma.Web.ActivityPub.Transmogrifier
7 alias Pleroma.Web.CommonAPI
8
9 import Pleroma.Factory
10
11 clear_config_all([:static_fe, :enabled]) do
12 Config.put([:static_fe, :enabled], true)
13 end
14
15 setup %{conn: conn} do
16 conn = put_req_header(conn, "accept", "text/html")
17 user = insert(:user)
18
19 %{conn: conn, user: user}
20 end
21
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}")
25
26 assert html_response(conn, 200) =~ user.nickname
27 end
28
29 test "404 when user not found", %{conn: conn} do
30 conn = get(conn, "/users/limpopo")
31
32 assert html_response(conn, 404) =~ "not found"
33 end
34
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"})
38
39 conn = get(conn, "/users/#{user.nickname}")
40
41 html = html_response(conn, 200)
42
43 assert html =~ ">public<"
44 refute html =~ ">private<"
45 end
46
47 test "pagination", %{conn: conn, user: user} do
48 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
49
50 conn = get(conn, "/users/#{user.nickname}")
51
52 html = html_response(conn, 200)
53
54 assert html =~ ">test30<"
55 assert html =~ ">test11<"
56 refute html =~ ">test10<"
57 refute html =~ ">test1<"
58 end
59
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)
63
64 conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
65
66 html = html_response(conn, 200)
67
68 assert html =~ ">test1<"
69 assert html =~ ">test10<"
70 refute html =~ ">test20<"
71 refute html =~ ">test29<"
72 end
73 end
74
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!"})
78
79 conn = get(conn, "/notice/#{activity.id}")
80
81 html = html_response(conn, 200)
82 assert html =~ "<header>"
83 assert html =~ user.nickname
84 assert html =~ "testing a thing!"
85 end
86
87 test "shows the whole thread", %{conn: conn, user: user} do
88 {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
89
90 CommonAPI.post(user, %{
91 "status" => "these are the voyages or something",
92 "in_reply_to_status_id" => activity.id
93 })
94
95 conn = get(conn, "/notice/#{activity.id}")
96
97 html = html_response(conn, 200)
98 assert html =~ "the final frontier"
99 assert html =~ "voyages"
100 end
101
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"})
105
106 conn = get(conn, URI.parse(object_url).path)
107
108 assert html_response(conn, 302) =~ "redirected"
109 end
110
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!"})
114
115 conn = get(conn, URI.parse(id).path)
116
117 assert html_response(conn, 302) =~ "redirected"
118 end
119
120 test "404 when notice not found", %{conn: conn} do
121 conn = get(conn, "/notice/88c9c317")
122
123 assert html_response(conn, 404) =~ "not found"
124 end
125
126 test "404 for private status", %{conn: conn, user: user} do
127 {:ok, activity} =
128 CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
129
130 conn = get(conn, "/notice/#{activity.id}")
131
132 assert html_response(conn, 404) =~ "not found"
133 end
134
135 test "302 for remote cached status", %{conn: conn, user: user} do
136 message = %{
137 "@context" => "https://www.w3.org/ns/activitystreams",
138 "to" => user.follower_address,
139 "cc" => "https://www.w3.org/ns/activitystreams#Public",
140 "type" => "Create",
141 "object" => %{
142 "content" => "blah blah blah",
143 "type" => "Note",
144 "attributedTo" => user.ap_id,
145 "inReplyTo" => nil
146 },
147 "actor" => user.ap_id
148 }
149
150 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
151
152 conn = get(conn, "/notice/#{activity.id}")
153
154 assert html_response(conn, 302) =~ "redirected"
155 end
156 end
157 end