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.FeedControllerTest do
6 use Pleroma.Web.ConnCase
13 test "gets a feed", %{conn: conn} do
14 activity = insert(:note_activity)
21 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}]
24 "inReplyTo" => activity.data["id"]
28 note_activity = insert(:note_activity, note: note)
29 object = Object.normalize(note_activity)
30 user = User.get_cached_by_ap_id(note_activity.data["actor"])
34 |> put_req_header("content-type", "application/atom+xml")
35 |> get("/users/#{user.nickname}/feed.atom")
37 assert response(conn, 200) =~ object.data["content"]
40 test "returns 404 for a missing feed", %{conn: conn} do
43 |> put_req_header("content-type", "application/atom+xml")
44 |> get("/users/nonexisting/feed.atom")
46 assert response(conn, 404)
49 describe "feed_redirect" do
50 test "undefined format. it redirects to feed", %{conn: conn} do
51 note_activity = insert(:note_activity)
52 user = User.get_cached_by_ap_id(note_activity.data["actor"])
56 |> put_req_header("accept", "application/xml")
57 |> get("/users/#{user.nickname}")
61 "<html><body>You are being <a href=\"#{Pleroma.Web.base_url()}/users/#{
63 }/feed.atom\">redirected</a>.</body></html>"
66 test "undefined format. it returns error when user not found", %{conn: conn} do
69 |> put_req_header("accept", "application/xml")
73 assert response == ~S({"error":"Not found"})
76 test "activity+json format. it redirects on actual feed of user", %{conn: conn} do
77 note_activity = insert(:note_activity)
78 user = User.get_cached_by_ap_id(note_activity.data["actor"])
82 |> put_req_header("accept", "application/activity+json")
83 |> get("/users/#{user.nickname}")
86 assert response["endpoints"] == %{
87 "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
88 "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
89 "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
90 "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
91 "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
94 assert response["@context"] == [
95 "https://www.w3.org/ns/activitystreams",
96 "http://localhost:4001/schemas/litepub-0.1.jsonld",
97 %{"@language" => "und"}
100 assert Map.take(response, [
105 "manuallyApprovesFollowers",
114 "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
115 "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
116 "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
117 "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
118 "manuallyApprovesFollowers" => false,
120 "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
121 "preferredUsername" => user.nickname,
122 "summary" => user.bio,
125 "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
129 test "activity+json format. it returns error whe use not found", %{conn: conn} do
132 |> put_req_header("accept", "application/activity+json")
133 |> get("/users/jimm")
134 |> json_response(404)
136 assert response == "Not found"
139 test "json format. it redirects on actual feed of user", %{conn: conn} do
140 note_activity = insert(:note_activity)
141 user = User.get_cached_by_ap_id(note_activity.data["actor"])
145 |> put_req_header("accept", "application/json")
146 |> get("/users/#{user.nickname}")
147 |> json_response(200)
149 assert response["endpoints"] == %{
150 "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
151 "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
152 "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
153 "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
154 "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
157 assert response["@context"] == [
158 "https://www.w3.org/ns/activitystreams",
159 "http://localhost:4001/schemas/litepub-0.1.jsonld",
160 %{"@language" => "und"}
163 assert Map.take(response, [
168 "manuallyApprovesFollowers",
177 "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
178 "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
179 "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
180 "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
181 "manuallyApprovesFollowers" => false,
183 "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
184 "preferredUsername" => user.nickname,
185 "summary" => user.bio,
188 "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
192 test "json format. it returns error whe use not found", %{conn: conn} do
195 |> put_req_header("accept", "application/json")
196 |> get("/users/jimm")
197 |> json_response(404)
199 assert response == "Not found"
202 test "html format. it redirects on actual feed of user", %{conn: conn} do
203 note_activity = insert(:note_activity)
204 user = User.get_cached_by_ap_id(note_activity.data["actor"])
208 |> get("/users/#{user.nickname}")
212 Fallback.RedirectController.redirector_with_meta(
218 test "html format. it returns error when user not found", %{conn: conn} do
221 |> get("/users/jimm")
222 |> json_response(404)
224 assert response == %{"error" => "Not found"}