1 defmodule Pleroma.Activity.Ir.TopicsTest do
5 alias Pleroma.Activity.Ir.Topics
8 require Pleroma.Constants
10 describe "poll answer" do
11 test "produce no topics" do
12 activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
14 assert [] == Topics.get_activity_topics(activity)
18 describe "non poll answer" do
19 test "always add user and list topics" do
20 activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
21 topics = Topics.get_activity_topics(activity)
23 assert Enum.member?(topics, "user")
24 assert Enum.member?(topics, "list")
28 describe "public visibility" do
31 object: %Object{data: %{"type" => "Note"}},
32 data: %{"to" => [Pleroma.Constants.as_public()]}
35 {:ok, activity: activity}
38 test "produces public topic", %{activity: activity} do
39 topics = Topics.get_activity_topics(activity)
41 assert Enum.member?(topics, "public")
44 test "local action produces public:local topic", %{activity: activity} do
45 activity = %{activity | local: true}
46 topics = Topics.get_activity_topics(activity)
48 assert Enum.member?(topics, "public:local")
51 test "non-local action does not produce public:local topic", %{activity: activity} do
52 activity = %{activity | local: false}
53 topics = Topics.get_activity_topics(activity)
55 refute Enum.member?(topics, "public:local")
59 describe "public visibility create events" do
62 object: %Object{data: %{"attachment" => []}},
63 data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
66 {:ok, activity: activity}
69 test "with no attachments doesn't produce public:media topics", %{activity: activity} do
70 topics = Topics.get_activity_topics(activity)
72 refute Enum.member?(topics, "public:media")
73 refute Enum.member?(topics, "public:local:media")
76 test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
77 tagged_data = Map.put(data, "tag", ["foo", "bar"])
78 activity = %{activity | object: %{object | data: tagged_data}}
80 topics = Topics.get_activity_topics(activity)
82 assert Enum.member?(topics, "hashtag:foo")
83 assert Enum.member?(topics, "hashtag:bar")
86 test "only converts strinngs to hash tags", %{
87 activity: %{object: %{data: data} = object} = activity
89 tagged_data = Map.put(data, "tag", [2])
90 activity = %{activity | object: %{object | data: tagged_data}}
92 topics = Topics.get_activity_topics(activity)
94 refute Enum.member?(topics, "hashtag:2")
98 describe "public visibility create events with attachments" do
100 activity = %Activity{
101 object: %Object{data: %{"attachment" => ["foo"]}},
102 data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
105 {:ok, activity: activity}
108 test "produce public:media topics", %{activity: activity} do
109 topics = Topics.get_activity_topics(activity)
111 assert Enum.member?(topics, "public:media")
114 test "local produces public:local:media topics", %{activity: activity} do
115 topics = Topics.get_activity_topics(activity)
117 assert Enum.member?(topics, "public:local:media")
120 test "non-local doesn't produce public:local:media topics", %{activity: activity} do
121 activity = %{activity | local: false}
123 topics = Topics.get_activity_topics(activity)
125 refute Enum.member?(topics, "public:local:media")
129 describe "non-public visibility" do
130 test "produces direct topic" do
131 activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
132 topics = Topics.get_activity_topics(activity)
134 assert Enum.member?(topics, "direct")
135 refute Enum.member?(topics, "public")
136 refute Enum.member?(topics, "public:local")
137 refute Enum.member?(topics, "public:media")
138 refute Enum.member?(topics, "public:local:media")