1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Feed.TagControllerTest do
6 use Pleroma.Web.ConnCase
13 alias Pleroma.Web.CommonAPI
14 alias Pleroma.Web.Feed.FeedView
16 setup do: clear_config([:feed])
18 test "gets a feed (ATOM)", %{conn: conn} do
21 %{max_length: 25, omission: "..."}
25 {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
27 object = Object.normalize(activity1, fetch: false)
30 Map.put(object.data, "attachment", [
35 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
36 "mediaType" => "video/mp4",
44 |> Ecto.Changeset.change(data: object_data)
45 |> Pleroma.Repo.update()
47 {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
49 {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
53 |> put_req_header("accept", "application/atom+xml")
54 |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
59 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
61 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
62 '42 This is :moominmamm...',
66 assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
67 assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
71 |> put_req_header("accept", "application/atom+xml")
72 |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
74 assert get_resp_header(conn, "content-type") == ["application/atom+xml; charset=utf-8"]
75 resp = response(conn, 200)
78 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
80 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
85 test "gets a feed (RSS)", %{conn: conn} do
88 %{max_length: 25, omission: "..."}
92 {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
94 object = Object.normalize(activity1, fetch: false)
97 Map.put(object.data, "attachment", [
102 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
103 "mediaType" => "video/mp4",
111 |> Ecto.Changeset.change(data: object_data)
112 |> Pleroma.Repo.update()
114 {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
116 {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
120 |> put_req_header("accept", "application/rss+xml")
121 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
124 xml = parse(response)
125 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
127 assert xpath(xml, ~x"//channel/description/text()"s) ==
128 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
130 assert xpath(xml, ~x"//channel/link/text()") ==
131 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
133 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
134 '#{Pleroma.Web.base_url()}/static/logo.svg'
136 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
137 '42 This is :moominmamm...',
141 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
142 FeedView.pub_date(activity2.data["published"]),
143 FeedView.pub_date(activity1.data["published"])
146 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
147 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
150 obj1 = Object.normalize(activity1, fetch: false)
151 obj2 = Object.normalize(activity2, fetch: false)
153 assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
154 HtmlEntities.decode(FeedView.activity_content(obj2.data)),
155 HtmlEntities.decode(FeedView.activity_content(obj1.data))
160 |> put_req_header("accept", "application/rss+xml")
161 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
164 xml = parse(response)
165 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
167 assert xpath(xml, ~x"//channel/description/text()"s) ==
168 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
172 |> put_req_header("accept", "application/rss+xml")
173 |> get("/tags/pleromaart.rss", %{"max_id" => activity2.id})
175 assert get_resp_header(conn, "content-type") == ["application/rss+xml; charset=utf-8"]
176 resp = response(conn, 200)
179 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
181 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
186 describe "private instance" do
187 setup do: clear_config([:instance, :public], false)
189 test "returns 404 for tags feed", %{conn: conn} do
191 |> put_req_header("accept", "application/rss+xml")
192 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))