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("content-type", "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"]
73 test "returns 404 for a missing feed", %{conn: conn} do
76 |> put_req_header("content-type", "application/atom+xml")
77 |> get(user_feed_path(conn, :feed, "nonexisting"))
79 assert response(conn, 404)
83 # Note: see ActivityPubControllerTest for JSON format tests
84 describe "feed_redirect" do
85 test "with html format, it redirects to user feed", %{conn: conn} do
86 note_activity = insert(:note_activity)
87 user = User.get_cached_by_ap_id(note_activity.data["actor"])
91 |> get("/users/#{user.nickname}")
95 Fallback.RedirectController.redirector_with_meta(
101 test "with html format, it returns error when user is not found", %{conn: conn} do
104 |> get("/users/jimm")
105 |> json_response(404)
107 assert response == %{"error" => "Not found"}
110 test "with non-html / non-json format, it redirects to user feed in atom format", %{
113 note_activity = insert(:note_activity)
114 user = User.get_cached_by_ap_id(note_activity.data["actor"])
118 |> put_req_header("accept", "application/xml")
119 |> get("/users/#{user.nickname}")
121 assert conn.status == 302
122 assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
125 test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
128 |> put_req_header("accept", "application/xml")
129 |> get(user_feed_path(conn, :feed, "jimm"))
132 assert response == ~S({"error":"Not found"})