Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / pleroma / web / feed / tag_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Feed.TagControllerTest do
6 use Pleroma.Web.ConnCase
7
8 import Pleroma.Factory
9 import SweetXml
10
11 alias Pleroma.Config
12 alias Pleroma.Object
13 alias Pleroma.Web.CommonAPI
14 alias Pleroma.Web.Feed.FeedView
15
16 setup do: clear_config([:feed])
17
18 test "gets a feed (ATOM)", %{conn: conn} do
19 Config.put(
20 [:feed, :post_title],
21 %{max_length: 25, omission: "..."}
22 )
23
24 user = insert(:user)
25 {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
26
27 object = Object.normalize(activity1)
28
29 object_data =
30 Map.put(object.data, "attachment", [
31 %{
32 "url" => [
33 %{
34 "href" =>
35 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
36 "mediaType" => "video/mp4",
37 "type" => "Link"
38 }
39 ]
40 }
41 ])
42
43 object
44 |> Ecto.Changeset.change(data: object_data)
45 |> Pleroma.Repo.update()
46
47 {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
48
49 {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
50
51 response =
52 conn
53 |> put_req_header("accept", "application/atom+xml")
54 |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
55 |> response(200)
56
57 xml = parse(response)
58
59 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
60
61 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
62 '42 This is :moominmamm...',
63 'yeah #PleromaArt'
64 ]
65
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]
68
69 conn =
70 conn
71 |> put_req_header("accept", "application/atom+xml")
72 |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
73
74 assert get_resp_header(conn, "content-type") == ["application/atom+xml; charset=utf-8"]
75 resp = response(conn, 200)
76 xml = parse(resp)
77
78 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
79
80 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
81 'yeah #PleromaArt'
82 ]
83 end
84
85 test "gets a feed (RSS)", %{conn: conn} do
86 Config.put(
87 [:feed, :post_title],
88 %{max_length: 25, omission: "..."}
89 )
90
91 user = insert(:user)
92 {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
93
94 object = Object.normalize(activity1)
95
96 object_data =
97 Map.put(object.data, "attachment", [
98 %{
99 "url" => [
100 %{
101 "href" =>
102 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
103 "mediaType" => "video/mp4",
104 "type" => "Link"
105 }
106 ]
107 }
108 ])
109
110 object
111 |> Ecto.Changeset.change(data: object_data)
112 |> Pleroma.Repo.update()
113
114 {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
115
116 {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
117
118 response =
119 conn
120 |> put_req_header("accept", "application/rss+xml")
121 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
122 |> response(200)
123
124 xml = parse(response)
125 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
126
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."
129
130 assert xpath(xml, ~x"//channel/link/text()") ==
131 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
132
133 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
134 '#{Pleroma.Web.base_url()}/static/logo.png'
135
136 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
137 '42 This is :moominmamm...',
138 'yeah #PleromaArt'
139 ]
140
141 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
142 FeedView.pub_date(activity2.data["published"]),
143 FeedView.pub_date(activity1.data["published"])
144 ]
145
146 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
147 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
148 ]
149
150 obj1 = Object.normalize(activity1)
151 obj2 = Object.normalize(activity2)
152
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))
156 ]
157
158 response =
159 conn
160 |> put_req_header("accept", "application/rss+xml")
161 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
162 |> response(200)
163
164 xml = parse(response)
165 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
166
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."
169
170 conn =
171 conn
172 |> put_req_header("accept", "application/rss+xml")
173 |> get("/tags/pleromaart.rss", %{"max_id" => activity2.id})
174
175 assert get_resp_header(conn, "content-type") == ["application/rss+xml; charset=utf-8"]
176 resp = response(conn, 200)
177 xml = parse(resp)
178
179 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
180
181 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
182 'yeah #PleromaArt'
183 ]
184 end
185
186 describe "private instance" do
187 setup do: clear_config([:instance, :public], false)
188
189 test "returns 404 for tags feed", %{conn: conn} do
190 conn
191 |> put_req_header("accept", "application/rss+xml")
192 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
193 |> response(404)
194 end
195 end
196 end