logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

topics_test.exs (8040B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Activity.Ir.TopicsTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.Activity.Ir.Topics
  8. alias Pleroma.Object
  9. require Pleroma.Constants
  10. import Mock
  11. describe "chat message" do
  12. test "Create produces no topics" do
  13. activity = %Activity{
  14. object: %Object{data: %{"type" => "ChatMessage"}},
  15. data: %{"type" => "Create"}
  16. }
  17. assert [] == Topics.get_activity_topics(activity)
  18. end
  19. test "Delete produces user and user:pleroma_chat" do
  20. activity = %Activity{
  21. object: %Object{data: %{"type" => "ChatMessage"}},
  22. data: %{"type" => "Delete"}
  23. }
  24. topics = Topics.get_activity_topics(activity)
  25. assert [_, _] = topics
  26. assert "user" in topics
  27. assert "user:pleroma_chat" in topics
  28. end
  29. end
  30. describe "poll answer" do
  31. test "produce no topics" do
  32. activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
  33. assert [] == Topics.get_activity_topics(activity)
  34. end
  35. end
  36. describe "non poll answer" do
  37. test "always add user and list topics" do
  38. activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
  39. topics = Topics.get_activity_topics(activity)
  40. assert Enum.member?(topics, "user")
  41. assert Enum.member?(topics, "list")
  42. end
  43. end
  44. describe "public visibility" do
  45. setup do
  46. activity = %Activity{
  47. object: %Object{data: %{"type" => "Note"}},
  48. data: %{"to" => [Pleroma.Constants.as_public()], "type" => "Create"}
  49. }
  50. {:ok, activity: activity}
  51. end
  52. test "produces public topic", %{activity: activity} do
  53. topics = Topics.get_activity_topics(activity)
  54. assert Enum.member?(topics, "public")
  55. end
  56. test "local action produces public:local topic", %{activity: activity} do
  57. activity = %{activity | local: true}
  58. topics = Topics.get_activity_topics(activity)
  59. assert Enum.member?(topics, "public:local")
  60. end
  61. test "non-local action does not produce public:local topic", %{activity: activity} do
  62. activity = %{activity | local: false}
  63. topics = Topics.get_activity_topics(activity)
  64. refute Enum.member?(topics, "public:local")
  65. end
  66. end
  67. describe "public visibility create events" do
  68. setup do
  69. activity = %Activity{
  70. object: %Object{data: %{"attachment" => []}},
  71. data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
  72. }
  73. {:ok, activity: activity}
  74. end
  75. test "with no attachments doesn't produce public:media topics", %{activity: activity} do
  76. topics = Topics.get_activity_topics(activity)
  77. refute Enum.member?(topics, "public:media")
  78. refute Enum.member?(topics, "public:local:media")
  79. end
  80. test "converts tags to hash tags", %{activity: activity} do
  81. with_mock(Object, [:passthrough], hashtags: fn _ -> ["foo", "bar"] end) do
  82. topics = Topics.get_activity_topics(activity)
  83. assert Enum.member?(topics, "hashtag:foo")
  84. assert Enum.member?(topics, "hashtag:bar")
  85. end
  86. end
  87. test "only converts strings to hash tags", %{
  88. activity: %{object: %{data: data} = object} = activity
  89. } do
  90. tagged_data = Map.put(data, "tag", [2])
  91. activity = %{activity | object: %{object | data: tagged_data}}
  92. topics = Topics.get_activity_topics(activity)
  93. refute Enum.member?(topics, "hashtag:2")
  94. end
  95. test "non-local action produces public:remote topic", %{activity: activity} do
  96. activity = %{activity | local: false, actor: "https://lain.com/users/lain"}
  97. topics = Topics.get_activity_topics(activity)
  98. assert Enum.member?(topics, "public:remote:lain.com")
  99. end
  100. test "local action doesn't produce public:remote topic", %{activity: activity} do
  101. activity = %{activity | local: true, actor: "https://lain.com/users/lain"}
  102. topics = Topics.get_activity_topics(activity)
  103. refute Enum.member?(topics, "public:remote:lain.com")
  104. end
  105. end
  106. describe "public visibility Announces" do
  107. setup do
  108. activity = %Activity{
  109. object: %Object{data: %{"attachment" => []}},
  110. data: %{"type" => "Announce", "to" => [Pleroma.Constants.as_public()]}
  111. }
  112. {:ok, activity: activity}
  113. end
  114. test "does not generate public topics", %{activity: activity} do
  115. topics = Topics.get_activity_topics(activity)
  116. refute "public" in topics
  117. refute "public:remote" in topics
  118. refute "public:local" in topics
  119. end
  120. end
  121. describe "local-public visibility create events" do
  122. setup do
  123. activity = %Activity{
  124. object: %Object{data: %{"attachment" => []}},
  125. data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]}
  126. }
  127. {:ok, activity: activity}
  128. end
  129. test "doesn't produce public topics", %{activity: activity} do
  130. topics = Topics.get_activity_topics(activity)
  131. refute Enum.member?(topics, "public")
  132. end
  133. test "produces public:local topics", %{activity: activity} do
  134. topics = Topics.get_activity_topics(activity)
  135. assert Enum.member?(topics, "public:local")
  136. end
  137. test "with no attachments doesn't produce public:media topics", %{activity: activity} do
  138. topics = Topics.get_activity_topics(activity)
  139. refute Enum.member?(topics, "public:media")
  140. refute Enum.member?(topics, "public:local:media")
  141. end
  142. end
  143. describe "public visibility create events with attachments" do
  144. setup do
  145. activity = %Activity{
  146. object: %Object{data: %{"attachment" => ["foo"]}},
  147. data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
  148. }
  149. {:ok, activity: activity}
  150. end
  151. test "produce public:media topics", %{activity: activity} do
  152. topics = Topics.get_activity_topics(activity)
  153. assert Enum.member?(topics, "public:media")
  154. end
  155. test "local produces public:local:media topics", %{activity: activity} do
  156. topics = Topics.get_activity_topics(activity)
  157. assert Enum.member?(topics, "public:local:media")
  158. end
  159. test "non-local doesn't produce public:local:media topics", %{activity: activity} do
  160. activity = %{activity | local: false}
  161. topics = Topics.get_activity_topics(activity)
  162. refute Enum.member?(topics, "public:local:media")
  163. end
  164. test "non-local action produces public:remote:media topic", %{activity: activity} do
  165. activity = %{activity | local: false, actor: "https://lain.com/users/lain"}
  166. topics = Topics.get_activity_topics(activity)
  167. assert Enum.member?(topics, "public:remote:media:lain.com")
  168. end
  169. end
  170. describe "local-public visibility create events with attachments" do
  171. setup do
  172. activity = %Activity{
  173. object: %Object{data: %{"attachment" => ["foo"]}},
  174. data: %{"type" => "Create", "to" => [Pleroma.Web.ActivityPub.Utils.as_local_public()]}
  175. }
  176. {:ok, activity: activity}
  177. end
  178. test "do not produce public:media topics", %{activity: activity} do
  179. topics = Topics.get_activity_topics(activity)
  180. refute Enum.member?(topics, "public:media")
  181. end
  182. test "produces public:local:media topics", %{activity: activity} do
  183. topics = Topics.get_activity_topics(activity)
  184. assert Enum.member?(topics, "public:local:media")
  185. end
  186. end
  187. describe "non-public visibility" do
  188. test "produces direct topic" do
  189. activity = %Activity{
  190. object: %Object{data: %{"type" => "Note"}},
  191. data: %{"to" => [], "type" => "Create"}
  192. }
  193. topics = Topics.get_activity_topics(activity)
  194. assert Enum.member?(topics, "direct")
  195. refute Enum.member?(topics, "public")
  196. refute Enum.member?(topics, "public:local")
  197. refute Enum.member?(topics, "public:media")
  198. refute Enum.member?(topics, "public:local:media")
  199. end
  200. end
  201. end