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