make test fail everytime
[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 setup do: 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("accept", "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 conn =
69 conn
70 |> put_req_header("accept", "application/atom+xml")
71 |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
72
73 assert get_resp_header(conn, "content-type") == ["application/atom+xml; charset=utf-8"]
74 resp = response(conn, 200)
75 xml = parse(resp)
76
77 assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
78
79 assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
80 'yeah #PleromaArt'
81 ]
82 end
83
84 test "gets a feed (RSS)", %{conn: conn} do
85 %{microsecond: {micro, _}} = DateTime.utc_now()
86 micro = (micro / 1000) |> floor()
87 Process.sleep(950 - micro)
88
89 Pleroma.Config.put(
90 [:feed, :post_title],
91 %{max_length: 25, omission: "..."}
92 )
93
94 user = insert(:user)
95 {:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
96
97 object = Object.normalize(activity1)
98
99 object_data =
100 Map.put(object.data, "attachment", [
101 %{
102 "url" => [
103 %{
104 "href" =>
105 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
106 "mediaType" => "video/mp4",
107 "type" => "Link"
108 }
109 ]
110 }
111 ])
112
113 object
114 |> Ecto.Changeset.change(data: object_data)
115 |> Pleroma.Repo.update()
116
117 {:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
118
119 {:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
120
121 response =
122 conn
123 |> put_req_header("accept", "application/rss+xml")
124 |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
125 |> response(200)
126
127 xml = parse(response)
128 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
129
130 assert xpath(xml, ~x"//channel/description/text()"s) ==
131 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
132
133 assert xpath(xml, ~x"//channel/link/text()") ==
134 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
135
136 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
137 '#{Pleroma.Web.base_url()}/static/logo.png'
138
139 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
140 '42 This is :moominmamm...',
141 'yeah #PleromaArt'
142 ]
143
144 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
145 FeedView.pub_date(activity1.data["published"]),
146 FeedView.pub_date(activity2.data["published"])
147 ]
148
149 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
150 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
151 ]
152
153 obj1 = Object.normalize(activity1)
154 obj2 = Object.normalize(activity2)
155
156 assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
157 HtmlEntities.decode(FeedView.activity_content(obj2.data)),
158 HtmlEntities.decode(FeedView.activity_content(obj1.data))
159 ]
160
161 response =
162 conn
163 |> put_req_header("accept", "application/rss+xml")
164 |> get(tag_feed_path(conn, :feed, "pleromaart"))
165 |> response(200)
166
167 xml = parse(response)
168 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
169
170 assert xpath(xml, ~x"//channel/description/text()"s) ==
171 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
172
173 conn =
174 conn
175 |> put_req_header("accept", "application/rss+xml")
176 |> get("/tags/pleromaart.rss", %{"max_id" => activity2.id})
177
178 assert get_resp_header(conn, "content-type") == ["application/rss+xml; charset=utf-8"]
179 resp = response(conn, 200)
180 xml = parse(resp)
181
182 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
183
184 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
185 'yeah #PleromaArt'
186 ]
187 end
188 end