1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
14 alias Pleroma.Web.CommonAPI
16 setup do: clear_config([:instance, :federating], true)
19 setup do: clear_config([:feed])
21 test "gets an atom feed", %{conn: conn} do
24 %{max_length: 10, omission: "..."}
27 activity = insert(:note_activity)
32 "content" => "This is :moominmamma: note ",
36 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
40 "inReplyTo" => activity.data["id"]
44 note_activity = insert(:note_activity, note: note)
45 user = User.get_cached_by_ap_id(note_activity.data["actor"])
51 "content" => "42 This is :moominmamma: note ",
52 "inReplyTo" => activity.data["id"]
56 note_activity2 = insert(:note_activity, note: note2)
57 object = Object.normalize(note_activity)
61 |> put_req_header("accept", "application/atom+xml")
62 |> get(user_feed_path(conn, :feed, user.nickname))
68 |> SweetXml.xpath(~x"//entry/title/text()"l)
70 assert activity_titles == ['42 This...', 'This is...']
71 assert resp =~ object.data["content"]
75 |> put_req_header("accept", "application/atom+xml")
76 |> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
82 |> SweetXml.xpath(~x"//entry/title/text()"l)
84 assert activity_titles == ['This is...']
87 test "gets a rss feed", %{conn: conn} do
90 %{max_length: 10, omission: "..."}
93 activity = insert(:note_activity)
98 "content" => "This is :moominmamma: note ",
102 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
106 "inReplyTo" => activity.data["id"]
110 note_activity = insert(:note_activity, note: note)
111 user = User.get_cached_by_ap_id(note_activity.data["actor"])
117 "content" => "42 This is :moominmamma: note ",
118 "inReplyTo" => activity.data["id"]
122 note_activity2 = insert(:note_activity, note: note2)
123 object = Object.normalize(note_activity)
127 |> put_req_header("accept", "application/rss+xml")
128 |> get("/users/#{user.nickname}/feed.rss")
134 |> SweetXml.xpath(~x"//item/title/text()"l)
136 assert activity_titles == ['42 This...', 'This is...']
137 assert resp =~ object.data["content"]
141 |> put_req_header("accept", "application/rss+xml")
142 |> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id})
148 |> SweetXml.xpath(~x"//item/title/text()"l)
150 assert activity_titles == ['This is...']
153 test "returns 404 for a missing feed", %{conn: conn} do
156 |> put_req_header("accept", "application/atom+xml")
157 |> get(user_feed_path(conn, :feed, "nonexisting"))
159 assert response(conn, 404)
162 test "returns feed with public and unlisted activities", %{conn: conn} do
165 {:ok, _} = CommonAPI.post(user, %{status: "public", visibility: "public"})
166 {:ok, _} = CommonAPI.post(user, %{status: "direct", visibility: "direct"})
167 {:ok, _} = CommonAPI.post(user, %{status: "unlisted", visibility: "unlisted"})
168 {:ok, _} = CommonAPI.post(user, %{status: "private", visibility: "private"})
172 |> put_req_header("accept", "application/atom+xml")
173 |> get(user_feed_path(conn, :feed, user.nickname))
179 |> SweetXml.xpath(~x"//entry/title/text()"l)
182 assert activity_titles == ['public', 'unlisted']
186 # Note: see ActivityPubControllerTest for JSON format tests
187 describe "feed_redirect" do
188 test "with html format, it redirects to user feed", %{conn: conn} do
189 note_activity = insert(:note_activity)
190 user = User.get_cached_by_ap_id(note_activity.data["actor"])
194 |> get("/users/#{user.nickname}")
198 Fallback.RedirectController.redirector_with_meta(
204 test "with html format, it returns error when user is not found", %{conn: conn} do
207 |> get("/users/jimm")
208 |> json_response(404)
210 assert response == %{"error" => "Not found"}
213 test "with non-html / non-json format, it redirects to user feed in atom format", %{
216 note_activity = insert(:note_activity)
217 user = User.get_cached_by_ap_id(note_activity.data["actor"])
221 |> put_req_header("accept", "application/xml")
222 |> get("/users/#{user.nickname}")
224 assert conn.status == 302
225 assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
228 test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
231 |> put_req_header("accept", "application/xml")
232 |> get(user_feed_path(conn, :feed, "jimm"))
235 assert response == ~S({"error":"Not found"})