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.TagControllerTest do
6 use Pleroma.Web.ConnCase
12 alias Pleroma.Web.CommonAPI
13 alias Pleroma.Web.Feed.FeedView
15 setup do: clear_config([:feed])
17 test "gets a feed (ATOM)", %{conn: conn} do
20 %{max_length: 25, omission: "..."}
24 {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
26 object = Object.normalize(activity1)
29 Map.put(object.data, "attachment", [
34 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
35 "mediaType" => "video/mp4",
43 |> Ecto.Changeset.change(data: object_data)
44 |> Pleroma.Repo.update()
46 {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
48 {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
52 |> put_req_header("accept", "application/atom+xml")
53 |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
58 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
60 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
61 '42 This is :moominmamm...',
65 assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
66 assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
70 |> put_req_header("accept", "application/atom+xml")
71 |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
73 assert get_resp_header(conn, "content-type") == ["application/atom+xml; charset=utf-8"]
74 resp = response(conn, 200)
77 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
79 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
84 test "gets a feed (RSS)", %{conn: conn} do
87 %{max_length: 25, omission: "..."}
91 {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
93 object = Object.normalize(activity1)
96 Map.put(object.data, "attachment", [
101 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
102 "mediaType" => "video/mp4",
110 |> Ecto.Changeset.change(data: object_data)
111 |> Pleroma.Repo.update()
113 {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
115 {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
119 |> put_req_header("accept", "application/rss+xml")
120 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
123 xml = parse(response)
124 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
126 assert xpath(xml, ~x"//channel/description/text()"s) ==
127 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
129 assert xpath(xml, ~x"//channel/link/text()") ==
130 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
132 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
133 '#{Pleroma.Web.base_url()}/static/logo.png'
135 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
136 '42 This is :moominmamm...',
140 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
141 FeedView.pub_date(activity1.data["published"]),
142 FeedView.pub_date(activity2.data["published"])
145 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
146 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
149 obj1 = Object.normalize(activity1)
150 obj2 = Object.normalize(activity2)
152 assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
153 HtmlEntities.decode(FeedView.activity_content(obj2.data)),
154 HtmlEntities.decode(FeedView.activity_content(obj1.data))
159 |> put_req_header("accept", "application/rss+xml")
160 |> get(tag_feed_path(conn, :feed, "pleromaart"))
163 xml = parse(response)
164 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
166 assert xpath(xml, ~x"//channel/description/text()"s) ==
167 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
171 |> put_req_header("accept", "application/rss+xml")
172 |> get("/tags/pleromaart.rss", %{"max_id" => activity2.id})
174 assert get_resp_header(conn, "content-type") == ["application/rss+xml; charset=utf-8"]
175 resp = response(conn, 200)
178 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
180 assert xpath(xml, ~x"//channel/item/title/text()"l) == [