Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.1KB

  1. defmodule Pleroma.Activity.Ir.TopicsTest do
  2. use Pleroma.DataCase
  3. alias Pleroma.Activity
  4. alias Pleroma.Activity.Ir.Topics
  5. alias Pleroma.Object
  6. require Pleroma.Constants
  7. describe "poll answer" do
  8. test "produce no topics" do
  9. activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
  10. assert [] == Topics.get_activity_topics(activity)
  11. end
  12. end
  13. describe "non poll answer" do
  14. test "always add user and list topics" do
  15. activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
  16. topics = Topics.get_activity_topics(activity)
  17. assert Enum.member?(topics, "user")
  18. assert Enum.member?(topics, "list")
  19. end
  20. end
  21. describe "public visibility" do
  22. setup do
  23. activity = %Activity{
  24. object: %Object{data: %{"type" => "Note"}},
  25. data: %{"to" => [Pleroma.Constants.as_public()]}
  26. }
  27. {:ok, activity: activity}
  28. end
  29. test "produces public topic", %{activity: activity} do
  30. topics = Topics.get_activity_topics(activity)
  31. assert Enum.member?(topics, "public")
  32. end
  33. test "local action produces public:local topic", %{activity: activity} do
  34. activity = %{activity | local: true}
  35. topics = Topics.get_activity_topics(activity)
  36. assert Enum.member?(topics, "public:local")
  37. end
  38. test "non-local action does not produce public:local topic", %{activity: activity} do
  39. activity = %{activity | local: false}
  40. topics = Topics.get_activity_topics(activity)
  41. refute Enum.member?(topics, "public:local")
  42. end
  43. end
  44. describe "public visibility create events" do
  45. setup do
  46. activity = %Activity{
  47. object: %Object{data: %{"attachment" => []}},
  48. data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
  49. }
  50. {:ok, activity: activity}
  51. end
  52. test "with no attachments doesn't produce public:media topics", %{activity: activity} do
  53. topics = Topics.get_activity_topics(activity)
  54. refute Enum.member?(topics, "public:media")
  55. refute Enum.member?(topics, "public:local:media")
  56. end
  57. test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
  58. tagged_data = Map.put(data, "tag", ["foo", "bar"])
  59. activity = %{activity | object: %{object | data: tagged_data}}
  60. topics = Topics.get_activity_topics(activity)
  61. assert Enum.member?(topics, "hashtag:foo")
  62. assert Enum.member?(topics, "hashtag:bar")
  63. end
  64. test "only converts strings to hash tags", %{
  65. activity: %{object: %{data: data} = object} = activity
  66. } do
  67. tagged_data = Map.put(data, "tag", [2])
  68. activity = %{activity | object: %{object | data: tagged_data}}
  69. topics = Topics.get_activity_topics(activity)
  70. refute Enum.member?(topics, "hashtag:2")
  71. end
  72. end
  73. describe "public visibility create events with attachments" do
  74. setup do
  75. activity = %Activity{
  76. object: %Object{data: %{"attachment" => ["foo"]}},
  77. data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
  78. }
  79. {:ok, activity: activity}
  80. end
  81. test "produce public:media topics", %{activity: activity} do
  82. topics = Topics.get_activity_topics(activity)
  83. assert Enum.member?(topics, "public:media")
  84. end
  85. test "local produces public:local:media topics", %{activity: activity} do
  86. topics = Topics.get_activity_topics(activity)
  87. assert Enum.member?(topics, "public:local:media")
  88. end
  89. test "non-local doesn't produce public:local:media topics", %{activity: activity} do
  90. activity = %{activity | local: false}
  91. topics = Topics.get_activity_topics(activity)
  92. refute Enum.member?(topics, "public:local:media")
  93. end
  94. end
  95. describe "non-public visibility" do
  96. test "produces direct topic" do
  97. activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
  98. topics = Topics.get_activity_topics(activity)
  99. assert Enum.member?(topics, "direct")
  100. refute Enum.member?(topics, "public")
  101. refute Enum.member?(topics, "public:local")
  102. refute Enum.member?(topics, "public:media")
  103. refute Enum.member?(topics, "public:local:media")
  104. end
  105. end
  106. end