a56a1873828b04f44b8d23887fa670b9d82a136e
[akkoma] / test / web / feed / tag_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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", %{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.rss"))
53 |> response(200)
54
55 xml = parse(response)
56 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
57
58 assert xpath(xml, ~x"//channel/description/text()"s) ==
59 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
60
61 assert xpath(xml, ~x"//channel/link/text()") ==
62 '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
63
64 assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
65 '#{Pleroma.Web.base_url()}/static/logo.png'
66
67 assert xpath(xml, ~x"//channel/item/title/text()"l) == [
68 '42 This is :moominmamm...',
69 'yeah #PleromaArt'
70 ]
71
72 assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
73 FeedView.pub_date(activity1.data["published"]),
74 FeedView.pub_date(activity2.data["published"])
75 ]
76
77 assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
78 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
79 ]
80
81 obj1 = Pleroma.Object.normalize(activity1)
82 obj2 = Pleroma.Object.normalize(activity2)
83
84 assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
85 HtmlEntities.decode(FeedView.activity_content(obj2)),
86 HtmlEntities.decode(FeedView.activity_content(obj1))
87 ]
88
89 response =
90 conn
91 |> put_req_header("content-type", "application/atom+xml")
92 |> get(tag_feed_path(conn, :feed, "pleromaart"))
93 |> response(200)
94
95 xml = parse(response)
96 assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
97
98 assert xpath(xml, ~x"//channel/description/text()"s) ==
99 "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
100 end
101 end