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 clear_config([:instance, :federating]) do
16 Config.put([:instance, :federating], true)
22 test "gets a feed", %{conn: conn} do
25 %{max_length: 10, omission: "..."}
28 activity = insert(:note_activity)
33 "content" => "This is :moominmamma: note ",
37 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
41 "inReplyTo" => activity.data["id"]
45 note_activity = insert(:note_activity, note: note)
46 user = User.get_cached_by_ap_id(note_activity.data["actor"])
52 "content" => "42 This is :moominmamma: note ",
53 "inReplyTo" => activity.data["id"]
57 note_activity2 = insert(:note_activity, note: note2)
58 object = Object.normalize(note_activity)
62 |> put_req_header("accept", "application/atom+xml")
63 |> get(user_feed_path(conn, :feed, user.nickname))
69 |> SweetXml.xpath(~x"//entry/title/text()"l)
71 assert activity_titles == ['42 This...', 'This is...']
72 assert resp =~ object.data["content"]
76 |> put_req_header("accept", "application/atom+xml")
77 |> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
83 |> SweetXml.xpath(~x"//entry/title/text()"l)
85 assert activity_titles == ['This is...']
88 test "gets a rss feed", %{conn: conn} do
91 %{max_length: 10, omission: "..."}
94 activity = insert(:note_activity)
99 "content" => "This is :moominmamma: note ",
103 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
107 "inReplyTo" => activity.data["id"]
111 note_activity = insert(:note_activity, note: note)
112 user = User.get_cached_by_ap_id(note_activity.data["actor"])
118 "content" => "42 This is :moominmamma: note ",
119 "inReplyTo" => activity.data["id"]
123 note_activity2 = insert(:note_activity, note: note2)
124 object = Object.normalize(note_activity)
128 |> put_req_header("accept", "application/rss+xml")
129 |> get("/users/#{user.nickname}/feed.rss")
135 |> SweetXml.xpath(~x"//item/title/text()"l)
137 assert activity_titles == ['42 This...', 'This is...']
138 assert resp =~ object.data["content"]
142 |> put_req_header("accept", "application/rss+xml")
143 |> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id})
149 |> SweetXml.xpath(~x"//item/title/text()"l)
151 assert activity_titles == ['This is...']
154 test "returns 404 for a missing feed", %{conn: conn} do
157 |> put_req_header("accept", "application/atom+xml")
158 |> get(user_feed_path(conn, :feed, "nonexisting"))
160 assert response(conn, 404)
164 # Note: see ActivityPubControllerTest for JSON format tests
165 describe "feed_redirect" do
166 test "with html format, it redirects to user feed", %{conn: conn} do
167 note_activity = insert(:note_activity)
168 user = User.get_cached_by_ap_id(note_activity.data["actor"])
172 |> get("/users/#{user.nickname}")
176 Fallback.RedirectController.redirector_with_meta(
182 test "with html format, it returns error when user is not found", %{conn: conn} do
185 |> get("/users/jimm")
186 |> json_response(404)
188 assert response == %{"error" => "Not found"}
191 test "with non-html / non-json format, it redirects to user feed in atom format", %{
194 note_activity = insert(:note_activity)
195 user = User.get_cached_by_ap_id(note_activity.data["actor"])
199 |> put_req_header("accept", "application/xml")
200 |> get("/users/#{user.nickname}")
202 assert conn.status == 302
203 assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
206 test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
209 |> put_req_header("accept", "application/xml")
210 |> get(user_feed_path(conn, :feed, "jimm"))
213 assert response == ~S({"error":"Not found"})