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.TagControllerTest do
6 use Pleroma.Web.ConnCase
11 alias Pleroma.Web.Feed.FeedView
15 test "gets a feed (ATOM)", %{conn: conn} do
18 %{max_length: 25, omission: "..."}
22 {:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
24 object = Pleroma.Object.normalize(activity1)
27 Map.put(object.data, "attachment", [
32 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
33 "mediaType" => "video/mp4",
41 |> Ecto.Changeset.change(data: object_data)
42 |> Pleroma.Repo.update()
45 Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
47 {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"})
51 |> put_req_header("content-type", "application/atom+xml")
52 |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
57 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
59 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
60 '42 This is :moominmamm...',
64 assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
65 assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
68 test "gets a feed (RSS)", %{conn: conn} do
71 %{max_length: 25, omission: "..."}
75 {:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
77 object = Pleroma.Object.normalize(activity1)
80 Map.put(object.data, "attachment", [
85 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
86 "mediaType" => "video/mp4",
94 |> Ecto.Changeset.change(data: object_data)
95 |> Pleroma.Repo.update()
98 Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
100 {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"})
104 |> put_req_header("content-type", "application/rss+xml")
105 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
108 xml = parse(response)
109 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
111 assert xpath(xml, ~x"//channel/description/text()"s) ==
112 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
114 assert xpath(xml, ~x"//channel/link/text()") ==
115 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
117 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
118 '#{Pleroma.Web.base_url()}/static/logo.png'
120 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
121 '42 This is :moominmamm...',
125 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
126 FeedView.pub_date(activity1.data["published"]),
127 FeedView.pub_date(activity2.data["published"])
130 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
131 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
134 obj1 = Pleroma.Object.normalize(activity1)
135 obj2 = Pleroma.Object.normalize(activity2)
137 assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
138 HtmlEntities.decode(FeedView.activity_content(obj2)),
139 HtmlEntities.decode(FeedView.activity_content(obj1))
144 |> put_req_header("content-type", "application/atom+xml")
145 |> get(tag_feed_path(conn, :feed, "pleromaart"))
148 xml = parse(response)
149 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
151 assert xpath(xml, ~x"//channel/description/text()"s) ==
152 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."