1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Feed.UserControllerTest do
6 use Pleroma.Web.ConnCase
16 test "gets a feed", %{conn: conn} do
19 %{max_length: 10, omission: "..."}
22 activity = insert(:note_activity)
27 "content" => "This is :moominmamma: note ",
30 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}]
33 "inReplyTo" => activity.data["id"]
37 note_activity = insert(:note_activity, note: note)
38 user = User.get_cached_by_ap_id(note_activity.data["actor"])
43 data: %{"content" => "42 This is :moominmamma: note ", "inReplyTo" => activity.data["id"]}
46 _note_activity2 = insert(:note_activity, note: note2)
47 object = Object.normalize(note_activity)
51 |> put_req_header("content-type", "application/atom+xml")
52 |> get(user_feed_path(conn, :feed, user.nickname))
58 |> SweetXml.xpath(~x"//entry/title/text()"l)
60 assert activity_titles == ['42 This...', 'This is...']
61 assert resp =~ object.data["content"]
64 test "returns 404 for a missing feed", %{conn: conn} do
67 |> put_req_header("content-type", "application/atom+xml")
68 |> get(user_feed_path(conn, :feed, "nonexisting"))
70 assert response(conn, 404)
73 describe "feed_redirect" do
74 test "undefined format. it redirects to feed", %{conn: conn} do
75 note_activity = insert(:note_activity)
76 user = User.get_cached_by_ap_id(note_activity.data["actor"])
80 |> put_req_header("accept", "application/xml")
81 |> get("/users/#{user.nickname}")
85 "<html><body>You are being <a href=\"#{Pleroma.Web.base_url()}/users/#{
87 }/feed.atom\">redirected</a>.</body></html>"
90 test "undefined format. it returns error when user not found", %{conn: conn} do
93 |> put_req_header("accept", "application/xml")
94 |> get(user_feed_path(conn, :feed, "jimm"))
97 assert response == ~S({"error":"Not found"})
100 test "activity+json format. it redirects on actual feed of user", %{conn: conn} do
101 note_activity = insert(:note_activity)
102 user = User.get_cached_by_ap_id(note_activity.data["actor"])
106 |> put_req_header("accept", "application/activity+json")
107 |> get("/users/#{user.nickname}")
108 |> json_response(200)
110 assert response["endpoints"] == %{
111 "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
112 "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
113 "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
114 "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
115 "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
118 assert response["@context"] == [
119 "https://www.w3.org/ns/activitystreams",
120 "http://localhost:4001/schemas/litepub-0.1.jsonld",
121 %{"@language" => "und"}
124 assert Map.take(response, [
129 "manuallyApprovesFollowers",
138 "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
139 "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
140 "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
141 "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
142 "manuallyApprovesFollowers" => false,
144 "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
145 "preferredUsername" => user.nickname,
146 "summary" => user.bio,
149 "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
153 test "activity+json format. it returns error whe use not found", %{conn: conn} do
156 |> put_req_header("accept", "application/activity+json")
157 |> get("/users/jimm")
158 |> json_response(404)
160 assert response == "Not found"
163 test "json format. it redirects on actual feed of user", %{conn: conn} do
164 note_activity = insert(:note_activity)
165 user = User.get_cached_by_ap_id(note_activity.data["actor"])
169 |> put_req_header("accept", "application/json")
170 |> get("/users/#{user.nickname}")
171 |> json_response(200)
173 assert response["endpoints"] == %{
174 "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
175 "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
176 "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
177 "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
178 "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
181 assert response["@context"] == [
182 "https://www.w3.org/ns/activitystreams",
183 "http://localhost:4001/schemas/litepub-0.1.jsonld",
184 %{"@language" => "und"}
187 assert Map.take(response, [
192 "manuallyApprovesFollowers",
201 "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
202 "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
203 "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
204 "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
205 "manuallyApprovesFollowers" => false,
207 "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
208 "preferredUsername" => user.nickname,
209 "summary" => user.bio,
212 "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
216 test "json format. it returns error whe use not found", %{conn: conn} do
219 |> put_req_header("accept", "application/json")
220 |> get("/users/jimm")
221 |> json_response(404)
223 assert response == "Not found"
226 test "html format. it redirects on actual feed of user", %{conn: conn} do
227 note_activity = insert(:note_activity)
228 user = User.get_cached_by_ap_id(note_activity.data["actor"])
232 |> get("/users/#{user.nickname}")
236 Fallback.RedirectController.redirector_with_meta(
242 test "html format. it returns error when user not found", %{conn: conn} do
245 |> get("/users/jimm")
246 |> json_response(404)
248 assert response == %{"error" => "Not found"}