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
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("content-type", "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("content-type", "application/atom+xml")
71 |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
76 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
78 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
83 test "gets a feed (RSS)", %{conn: conn} do
86 %{max_length: 25, omission: "..."}
90 {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
92 object = Object.normalize(activity1)
95 Map.put(object.data, "attachment", [
100 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
101 "mediaType" => "video/mp4",
109 |> Ecto.Changeset.change(data: object_data)
110 |> Pleroma.Repo.update()
112 {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
114 {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
118 |> put_req_header("content-type", "application/rss+xml")
119 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
122 xml = parse(response)
123 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
125 assert xpath(xml, ~x"//channel/description/text()"s) ==
126 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
128 assert xpath(xml, ~x"//channel/link/text()") ==
129 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
131 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
132 '#{Pleroma.Web.base_url()}/static/logo.png'
134 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
135 '42 This is :moominmamm...',
139 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
140 FeedView.pub_date(activity1.data["published"]),
141 FeedView.pub_date(activity2.data["published"])
144 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
145 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
148 obj1 = Object.normalize(activity1)
149 obj2 = Object.normalize(activity2)
151 assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
152 HtmlEntities.decode(FeedView.activity_content(obj2)),
153 HtmlEntities.decode(FeedView.activity_content(obj1))
158 |> put_req_header("content-type", "application/atom+xml")
159 |> get(tag_feed_path(conn, :feed, "pleromaart"))
162 xml = parse(response)
163 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
165 assert xpath(xml, ~x"//channel/description/text()"s) ==
166 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
170 |> put_req_header("content-type", "application/atom+xml")
171 |> get("/tags/pleromaart", %{"max_id" => activity2.id})
176 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
178 assert xpath(xml, ~x"//channel/item/title/text()"l) == [