logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

tag_controller_test.exs (6069B)


  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. defmodule Pleroma.Web.Feed.TagControllerTest do
  5. use Pleroma.Web.ConnCase
  6. import Pleroma.Factory
  7. import SweetXml
  8. alias Pleroma.Object
  9. alias Pleroma.Web.CommonAPI
  10. alias Pleroma.Web.Feed.FeedView
  11. setup do: clear_config([:feed])
  12. test "gets a feed (ATOM)", %{conn: conn} do
  13. Pleroma.Config.put(
  14. [:feed, :post_title],
  15. %{max_length: 25, omission: "..."}
  16. )
  17. user = insert(:user)
  18. {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
  19. object = Object.normalize(activity1)
  20. object_data =
  21. Map.put(object.data, "attachment", [
  22. %{
  23. "url" => [
  24. %{
  25. "href" =>
  26. "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
  27. "mediaType" => "video/mp4",
  28. "type" => "Link"
  29. }
  30. ]
  31. }
  32. ])
  33. object
  34. |> Ecto.Changeset.change(data: object_data)
  35. |> Pleroma.Repo.update()
  36. {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
  37. {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
  38. response =
  39. conn
  40. |> put_req_header("accept", "application/atom+xml")
  41. |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
  42. |> response(200)
  43. xml = parse(response)
  44. assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
  45. assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
  46. '42 This is :moominmamm...',
  47. 'yeah #PleromaArt'
  48. ]
  49. assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
  50. assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
  51. conn =
  52. conn
  53. |> put_req_header("accept", "application/atom+xml")
  54. |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
  55. assert get_resp_header(conn, "content-type") == ["application/atom+xml; charset=utf-8"]
  56. resp = response(conn, 200)
  57. xml = parse(resp)
  58. assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
  59. assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
  60. 'yeah #PleromaArt'
  61. ]
  62. end
  63. test "gets a feed (RSS)", %{conn: conn} do
  64. Pleroma.Config.put(
  65. [:feed, :post_title],
  66. %{max_length: 25, omission: "..."}
  67. )
  68. user = insert(:user)
  69. {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
  70. object = Object.normalize(activity1)
  71. object_data =
  72. Map.put(object.data, "attachment", [
  73. %{
  74. "url" => [
  75. %{
  76. "href" =>
  77. "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
  78. "mediaType" => "video/mp4",
  79. "type" => "Link"
  80. }
  81. ]
  82. }
  83. ])
  84. object
  85. |> Ecto.Changeset.change(data: object_data)
  86. |> Pleroma.Repo.update()
  87. {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
  88. {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
  89. response =
  90. conn
  91. |> put_req_header("accept", "application/rss+xml")
  92. |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
  93. |> response(200)
  94. xml = parse(response)
  95. assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
  96. assert xpath(xml, ~x"//channel/description/text()"s) ==
  97. "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
  98. assert xpath(xml, ~x"//channel/link/text()") ==
  99. '#{Pleroma.Web.base_url()}/tags/pleromaart.rss'
  100. assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
  101. '#{Pleroma.Web.base_url()}/static/logo.png'
  102. assert xpath(xml, ~x"//channel/item/title/text()"l) == [
  103. '42 This is :moominmamm...',
  104. 'yeah #PleromaArt'
  105. ]
  106. assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
  107. FeedView.pub_date(activity2.data["published"]),
  108. FeedView.pub_date(activity1.data["published"])
  109. ]
  110. assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
  111. "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
  112. ]
  113. obj1 = Object.normalize(activity1)
  114. obj2 = Object.normalize(activity2)
  115. assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
  116. HtmlEntities.decode(FeedView.activity_content(obj2.data)),
  117. HtmlEntities.decode(FeedView.activity_content(obj1.data))
  118. ]
  119. response =
  120. conn
  121. |> put_req_header("accept", "application/rss+xml")
  122. |> get(tag_feed_path(conn, :feed, "pleromaart"))
  123. |> response(200)
  124. xml = parse(response)
  125. assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
  126. assert xpath(xml, ~x"//channel/description/text()"s) ==
  127. "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
  128. conn =
  129. conn
  130. |> put_req_header("accept", "application/rss+xml")
  131. |> get("/tags/pleromaart.rss", %{"max_id" => activity2.id})
  132. assert get_resp_header(conn, "content-type") == ["application/rss+xml; charset=utf-8"]
  133. resp = response(conn, 200)
  134. xml = parse(resp)
  135. assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
  136. assert xpath(xml, ~x"//channel/item/title/text()"l) == [
  137. 'yeah #PleromaArt'
  138. ]
  139. end
  140. describe "private instance" do
  141. setup do: clear_config([:instance, :public])
  142. test "returns 404 for tags feed", %{conn: conn} do
  143. Config.put([:instance, :public], false)
  144. conn
  145. |> put_req_header("accept", "application/rss+xml")
  146. |> get(tag_feed_path(conn, :feed, "pleromaart"))
  147. |> response(404)
  148. end
  149. end
  150. end