1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Activity.Ir.TopicsTest do
9 alias Pleroma.Activity.Ir.Topics
12 require Pleroma.Constants
14 describe "poll answer" do
15 test "produce no topics" do
16 activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
18 assert [] == Topics.get_activity_topics(activity)
22 describe "non poll answer" do
23 test "always add user and list topics" do
24 activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
25 topics = Topics.get_activity_topics(activity)
27 assert Enum.member?(topics, "user")
28 assert Enum.member?(topics, "list")
32 describe "public visibility" do
35 object: %Object{data: %{"type" => "Note"}},
36 data: %{"to" => [Pleroma.Constants.as_public()]}
39 {:ok, activity: activity}
42 test "produces public topic", %{activity: activity} do
43 topics = Topics.get_activity_topics(activity)
45 assert Enum.member?(topics, "public")
48 test "local action produces public:local topic", %{activity: activity} do
49 activity = %{activity | local: true}
50 topics = Topics.get_activity_topics(activity)
52 assert Enum.member?(topics, "public:local")
55 test "non-local action does not produce public:local topic", %{activity: activity} do
56 activity = %{activity | local: false}
57 topics = Topics.get_activity_topics(activity)
59 refute Enum.member?(topics, "public:local")
63 describe "public visibility create events" do
66 object: %Object{data: %{"attachment" => []}},
67 data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
70 {:ok, activity: activity}
73 test "with no attachments doesn't produce public:media topics", %{activity: activity} do
74 topics = Topics.get_activity_topics(activity)
76 refute Enum.member?(topics, "public:media")
77 refute Enum.member?(topics, "public:local:media")
80 test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
81 tagged_data = Map.put(data, "tag", ["foo", "bar"])
82 activity = %{activity | object: %{object | data: tagged_data}}
84 topics = Topics.get_activity_topics(activity)
86 assert Enum.member?(topics, "hashtag:foo")
87 assert Enum.member?(topics, "hashtag:bar")
90 test "only converts strings to hash tags", %{
91 activity: %{object: %{data: data} = object} = activity
93 tagged_data = Map.put(data, "tag", [2])
94 activity = %{activity | object: %{object | data: tagged_data}}
96 topics = Topics.get_activity_topics(activity)
98 refute Enum.member?(topics, "hashtag:2")
102 describe "public visibility create events with attachments" do
104 activity = %Activity{
105 object: %Object{data: %{"attachment" => ["foo"]}},
106 data: %{"type" => "Create", "to" => [Pleroma.Constants.as_public()]}
109 {:ok, activity: activity}
112 test "produce public:media topics", %{activity: activity} do
113 topics = Topics.get_activity_topics(activity)
115 assert Enum.member?(topics, "public:media")
118 test "local produces public:local:media topics", %{activity: activity} do
119 topics = Topics.get_activity_topics(activity)
121 assert Enum.member?(topics, "public:local:media")
124 test "non-local doesn't produce public:local:media topics", %{activity: activity} do
125 activity = %{activity | local: false}
127 topics = Topics.get_activity_topics(activity)
129 refute Enum.member?(topics, "public:local:media")
133 describe "non-public visibility" do
134 test "produces direct topic" do
135 activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
136 topics = Topics.get_activity_topics(activity)
138 assert Enum.member?(topics, "direct")
139 refute Enum.member?(topics, "public")
140 refute Enum.member?(topics, "public:local")
141 refute Enum.member?(topics, "public:media")
142 refute Enum.member?(topics, "public:local:media")