summaryrefslogtreecommitdiff
path: root/test/web/feed/tag_controller_test.exs
blob: 5950605e8bc016dcf299c3173eea4a0538b3e5c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.Feed.TagControllerTest do
  use Pleroma.Web.ConnCase

  import Pleroma.Factory
  import SweetXml

  alias Pleroma.Web.Feed.FeedView

  clear_config([:feed])

  test "gets a feed (ATOM)", %{conn: conn} do
    Pleroma.Config.put(
      [:feed, :post_title],
      %{max_length: 25, omission: "..."}
    )

    user = insert(:user)
    {:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})

    object = Pleroma.Object.normalize(activity1)

    object_data =
      Map.put(object.data, "attachment", [
        %{
          "url" => [
            %{
              "href" =>
                "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
              "mediaType" => "video/mp4",
              "type" => "Link"
            }
          ]
        }
      ])

    object
    |> Ecto.Changeset.change(data: object_data)
    |> Pleroma.Repo.update()

    {:ok, _activity2} =
      Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})

    {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"})

    response =
      conn
      |> put_req_header("content-type", "application/atom+xml")
      |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
      |> response(200)

    xml = parse(response)

    assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'

    assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
             '42 This is :moominmamm...',
             'yeah #PleromaArt'
           ]

    assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
    assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
  end

  test "gets a feed (RSS)", %{conn: conn} do
    Pleroma.Config.put(
      [:feed, :post_title],
      %{max_length: 25, omission: "..."}
    )

    user = insert(:user)
    {:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})

    object = Pleroma.Object.normalize(activity1)

    object_data =
      Map.put(object.data, "attachment", [
        %{
          "url" => [
            %{
              "href" =>
                "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
              "mediaType" => "video/mp4",
              "type" => "Link"
            }
          ]
        }
      ])

    object
    |> Ecto.Changeset.change(data: object_data)
    |> Pleroma.Repo.update()

    {:ok, activity2} =
      Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})

    {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"})

    response =
      conn
      |> put_req_header("content-type", "application/rss+xml")
      |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
      |> response(200)

    xml = parse(response)
    assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'

    assert xpath(xml, ~x"//channel/description/text()"s) ==
             "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."

    assert xpath(xml, ~x"//channel/link/text()") ==
             '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'

    assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
             '#{Pleroma.Web.base_url()}/static/logo.png'

    assert xpath(xml, ~x"//channel/item/title/text()"l) == [
             '42 This is :moominmamm...',
             'yeah #PleromaArt'
           ]

    assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
             FeedView.pub_date(activity1.data["published"]),
             FeedView.pub_date(activity2.data["published"])
           ]

    assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
             "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
           ]

    obj1 = Pleroma.Object.normalize(activity1)
    obj2 = Pleroma.Object.normalize(activity2)

    assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
             HtmlEntities.decode(FeedView.activity_content(obj2)),
             HtmlEntities.decode(FeedView.activity_content(obj1))
           ]

    response =
      conn
      |> put_req_header("content-type", "application/atom+xml")
      |> get(tag_feed_path(conn, :feed, "pleromaart"))
      |> response(200)

    xml = parse(response)
    assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'

    assert xpath(xml, ~x"//channel/description/text()"s) ==
             "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
  end
end