c774bd420971c312fddcb7221c562cc030894246
[akkoma] / test / 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.Object
12 alias Pleroma.Web.CommonAPI
13 alias Pleroma.Web.Feed.FeedView
14
15 clear_config([:feed])
16
17 test "gets a feed (ATOM)", %{conn: conn} do
18 Pleroma.Config.put(
19 [:feed, :post_title],
20 %{max_length: 25, omission: "..."}
21 )
22
23 user = insert(:user)
24 {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
25
26 object = Object.normalize(activity1)
27
28 object_data =
29 Map.put(object.data, "attachment", [
30 %{
31 "url" => [
32 %{
33 "href" =>
34 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
35 "mediaType" => "video/mp4",
36 "type" => "Link"
37 }
38 ]
39 }
40 ])
41
42 object
43 |> Ecto.Changeset.change(data: object_data)
44 |> Pleroma.Repo.update()
45
46 {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
47
48 {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
49
50 response =
51 conn
52 |> put_req_header("content-type", "application/atom+xml")
53 |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
54 |> response(200)
55
56 xml = parse(response)
57
58 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
59
60 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
61 '42 This is :moominmamm...',
62 'yeah #PleromaArt'
63 ]
64
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]
67
68 resp =
69 conn
70 |> put_req_header("content-type", "application/atom+xml")
71 |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
72 |> response(200)
73
74 xml = parse(resp)
75
76 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
77
78 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
79 'yeah #PleromaArt'
80 ]
81 end
82
83 test "gets a feed (RSS)", %{conn: conn} do
84 Pleroma.Config.put(
85 [:feed, :post_title],
86 %{max_length: 25, omission: "..."}
87 )
88
89 user = insert(:user)
90 {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
91
92 object = Object.normalize(activity1)
93
94 object_data =
95 Map.put(object.data, "attachment", [
96 %{
97 "url" => [
98 %{
99 "href" =>
100 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
101 "mediaType" => "video/mp4",
102 "type" => "Link"
103 }
104 ]
105 }
106 ])
107
108 object
109 |> Ecto.Changeset.change(data: object_data)
110 |> Pleroma.Repo.update()
111
112 {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
113
114 {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
115
116 response =
117 conn
118 |> put_req_header("content-type", "application/rss+xml")
119 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
120 |> response(200)
121
122 xml = parse(response)
123 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
124
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."
127
128 assert xpath(xml, ~x"//channel/link/text()") ==
129 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
130
131 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
132 '#{Pleroma.Web.base_url()}/static/logo.png'
133
134 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
135 '42 This is :moominmamm...',
136 'yeah #PleromaArt'
137 ]
138
139 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
140 FeedView.pub_date(activity1.data["published"]),
141 FeedView.pub_date(activity2.data["published"])
142 ]
143
144 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
145 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
146 ]
147
148 obj1 = Object.normalize(activity1)
149 obj2 = Object.normalize(activity2)
150
151 assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
152 HtmlEntities.decode(FeedView.activity_content(obj2)),
153 HtmlEntities.decode(FeedView.activity_content(obj1))
154 ]
155
156 response =
157 conn
158 |> put_req_header("content-type", "application/atom+xml")
159 |> get(tag_feed_path(conn, :feed, "pleromaart"))
160 |> response(200)
161
162 xml = parse(response)
163 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
164
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."
167
168 resp =
169 conn
170 |> put_req_header("content-type", "application/atom+xml")
171 |> get("/tags/pleromaart", %{"max_id" => activity2.id})
172 |> response(200)
173
174 xml = parse(resp)
175
176 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
177
178 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
179 'yeah #PleromaArt'
180 ]
181 end
182 end