COPYING: Wording
[akkoma] / test / web / activity_pub / utils_test.exs
1 defmodule Pleroma.Web.ActivityPub.UtilsTest do
2 use Pleroma.DataCase
3 alias Pleroma.Web.CommonAPI
4 alias Pleroma.Web.ActivityPub.Utils
5
6 import Pleroma.Factory
7
8 describe "determine_explicit_mentions()" do
9 test "works with an object that has mentions" do
10 object = %{
11 "tag" => [
12 %{
13 "type" => "Mention",
14 "href" => "https://example.com/~alyssa",
15 "name" => "Alyssa P. Hacker"
16 }
17 ]
18 }
19
20 assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
21 end
22
23 test "works with an object that does not have mentions" do
24 object = %{
25 "tag" => [
26 %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
27 ]
28 }
29
30 assert Utils.determine_explicit_mentions(object) == []
31 end
32
33 test "works with an object that has mentions and other tags" do
34 object = %{
35 "tag" => [
36 %{
37 "type" => "Mention",
38 "href" => "https://example.com/~alyssa",
39 "name" => "Alyssa P. Hacker"
40 },
41 %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
42 ]
43 }
44
45 assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
46 end
47
48 test "works with an object that has no tags" do
49 object = %{}
50
51 assert Utils.determine_explicit_mentions(object) == []
52 end
53
54 test "works with an object that has only IR tags" do
55 object = %{"tag" => ["2hu"]}
56
57 assert Utils.determine_explicit_mentions(object) == []
58 end
59 end
60
61 describe "make_like_data" do
62 setup do
63 user = insert(:user)
64 other_user = insert(:user)
65 third_user = insert(:user)
66 [user: user, other_user: other_user, third_user: third_user]
67 end
68
69 test "addresses actor's follower address if the activity is public", %{
70 user: user,
71 other_user: other_user,
72 third_user: third_user
73 } do
74 expected_to = Enum.sort([user.ap_id, other_user.follower_address])
75 expected_cc = Enum.sort(["https://www.w3.org/ns/activitystreams#Public", third_user.ap_id])
76
77 {:ok, activity} =
78 CommonAPI.post(user, %{
79 "status" =>
80 "hey @#{other_user.nickname}, @#{third_user.nickname} how about beering together this weekend?"
81 })
82
83 %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
84 assert Enum.sort(to) == expected_to
85 assert Enum.sort(cc) == expected_cc
86 end
87
88 test "does not adress actor's follower address if the activity is not public", %{
89 user: user,
90 other_user: other_user,
91 third_user: third_user
92 } do
93 expected_to = Enum.sort([user.ap_id])
94 expected_cc = [third_user.ap_id]
95
96 {:ok, activity} =
97 CommonAPI.post(user, %{
98 "status" => "@#{other_user.nickname} @#{third_user.nickname} bought a new swimsuit!",
99 "visibility" => "private"
100 })
101
102 %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
103 assert Enum.sort(to) == expected_to
104 assert Enum.sort(cc) == expected_cc
105 end
106 end
107 end