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
15 setup do: clear_config([:instance, :federating], true)
18 setup do: clear_config([:feed])
20 test "gets a feed", %{conn: conn} do
23 %{max_length: 10, omission: "..."}
26 activity = insert(:note_activity)
31 "content" => "This is :moominmamma: note ",
35 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
39 "inReplyTo" => activity.data["id"]
43 note_activity = insert(:note_activity, note: note)
44 user = User.get_cached_by_ap_id(note_activity.data["actor"])
50 "content" => "42 This is :moominmamma: note ",
51 "inReplyTo" => activity.data["id"]
55 note_activity2 = insert(:note_activity, note: note2)
56 object = Object.normalize(note_activity)
60 |> put_req_header("accept", "application/atom+xml")
61 |> get(user_feed_path(conn, :feed, user.nickname))
67 |> SweetXml.xpath(~x"//entry/title/text()"l)
69 assert activity_titles == ['42 This...', 'This is...']
70 assert resp =~ object.data["content"]
74 |> put_req_header("accept", "application/atom+xml")
75 |> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
81 |> SweetXml.xpath(~x"//entry/title/text()"l)
83 assert activity_titles == ['This is...']
86 test "gets a rss feed", %{conn: conn} do
89 %{max_length: 10, omission: "..."}
92 activity = insert(:note_activity)
97 "content" => "This is :moominmamma: note ",
101 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
105 "inReplyTo" => activity.data["id"]
109 note_activity = insert(:note_activity, note: note)
110 user = User.get_cached_by_ap_id(note_activity.data["actor"])
116 "content" => "42 This is :moominmamma: note ",
117 "inReplyTo" => activity.data["id"]
121 note_activity2 = insert(:note_activity, note: note2)
122 object = Object.normalize(note_activity)
126 |> put_req_header("accept", "application/rss+xml")
127 |> get("/users/#{user.nickname}/feed.rss")
133 |> SweetXml.xpath(~x"//item/title/text()"l)
135 assert activity_titles == ['42 This...', 'This is...']
136 assert resp =~ object.data["content"]
140 |> put_req_header("accept", "application/rss+xml")
141 |> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id})
147 |> SweetXml.xpath(~x"//item/title/text()"l)
149 assert activity_titles == ['This is...']
152 test "returns 404 for a missing feed", %{conn: conn} do
155 |> put_req_header("accept", "application/atom+xml")
156 |> get(user_feed_path(conn, :feed, "nonexisting"))
158 assert response(conn, 404)
162 # Note: see ActivityPubControllerTest for JSON format tests
163 describe "feed_redirect" do
164 test "with html format, it redirects to user feed", %{conn: conn} do
165 note_activity = insert(:note_activity)
166 user = User.get_cached_by_ap_id(note_activity.data["actor"])
170 |> get("/users/#{user.nickname}")
174 Fallback.RedirectController.redirector_with_meta(
180 test "with html format, it returns error when user is not found", %{conn: conn} do
183 |> get("/users/jimm")
184 |> json_response(404)
186 assert response == %{"error" => "Not found"}
189 test "with non-html / non-json format, it redirects to user feed in atom format", %{
192 note_activity = insert(:note_activity)
193 user = User.get_cached_by_ap_id(note_activity.data["actor"])
197 |> put_req_header("accept", "application/xml")
198 |> get("/users/#{user.nickname}")
200 assert conn.status == 302
201 assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
204 test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
207 |> put_req_header("accept", "application/xml")
208 |> get(user_feed_path(conn, :feed, "jimm"))
211 assert response == ~S({"error":"Not found"})