Merge branch 'fix/1658-invite-send' into 'develop'
[akkoma] / test / activity / ir / topics_test.exs
1 defmodule Pleroma.Activity.Ir.TopicsTest do
2 use Pleroma.DataCase
3
4 alias Pleroma.Activity
5 alias Pleroma.Activity.Ir.Topics
6 alias Pleroma.Object
7
8 require Pleroma.Constants
9
10 describe "poll answer" do
11 test "produce no topics" do
12 activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
13
14 assert [] == Topics.get_activity_topics(activity)
15 end
16 end
17
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)
22
23 assert Enum.member?(topics, "user")
24 assert Enum.member?(topics, "list")
25 end
26 end
27
28 describe "public visibility" do
29 setup do
30 activity = %Activity{
31 object: %Object{data: %{"type" => "Note"}},
32 data: %{"to" => [Pleroma.Constants.as_public()]}
33 }
34
35 {:ok, activity: activity}
36 end
37
38 test "produces public topic", %{activity: activity} do
39 topics = Topics.get_activity_topics(activity)
40
41 assert Enum.member?(topics, "public")
42 end
43
44 test "local action produces public:local topic", %{activity: activity} do
45 activity = %{activity | local: true}
46 topics = Topics.get_activity_topics(activity)
47
48 assert Enum.member?(topics, "public:local")
49 end
50
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)
54
55 refute Enum.member?(topics, "public:local")
56 end
57 end
58
59 describe "public visibility create events" do
60 setup do
61 activity = %Activity{
62 object: %Object{data: %{"attachment" => []}},
63 data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
64 }
65
66 {:ok, activity: activity}
67 end
68
69 test "with no attachments doesn't produce public:media topics", %{activity: activity} do
70 topics = Topics.get_activity_topics(activity)
71
72 refute Enum.member?(topics, "public:media")
73 refute Enum.member?(topics, "public:local:media")
74 end
75
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}}
79
80 topics = Topics.get_activity_topics(activity)
81
82 assert Enum.member?(topics, "hashtag:foo")
83 assert Enum.member?(topics, "hashtag:bar")
84 end
85
86 test "only converts strings to hash tags", %{
87 activity: %{object: %{data: data} = object} = activity
88 } do
89 tagged_data = Map.put(data, "tag", [2])
90 activity = %{activity | object: %{object | data: tagged_data}}
91
92 topics = Topics.get_activity_topics(activity)
93
94 refute Enum.member?(topics, "hashtag:2")
95 end
96 end
97
98 describe "public visibility create events with attachments" do
99 setup do
100 activity = %Activity{
101 object: %Object{data: %{"attachment" => ["foo"]}},
102 data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
103 }
104
105 {:ok, activity: activity}
106 end
107
108 test "produce public:media topics", %{activity: activity} do
109 topics = Topics.get_activity_topics(activity)
110
111 assert Enum.member?(topics, "public:media")
112 end
113
114 test "local produces public:local:media topics", %{activity: activity} do
115 topics = Topics.get_activity_topics(activity)
116
117 assert Enum.member?(topics, "public:local:media")
118 end
119
120 test "non-local doesn't produce public:local:media topics", %{activity: activity} do
121 activity = %{activity | local: false}
122
123 topics = Topics.get_activity_topics(activity)
124
125 refute Enum.member?(topics, "public:local:media")
126 end
127 end
128
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)
133
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")
139 end
140 end
141 end