1 defmodule Pleroma.Web.ActivityPub.UtilsTest do
3 alias Pleroma.Web.CommonAPI
4 alias Pleroma.Web.ActivityPub.Utils
8 describe "determine_explicit_mentions()" do
9 test "works with an object that has mentions" do
14 "href" => "https://example.com/~alyssa",
15 "name" => "Alyssa P. Hacker"
20 assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
23 test "works with an object that does not have mentions" do
26 %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
30 assert Utils.determine_explicit_mentions(object) == []
33 test "works with an object that has mentions and other tags" do
38 "href" => "https://example.com/~alyssa",
39 "name" => "Alyssa P. Hacker"
41 %{"type" => "Hashtag", "href" => "https://example.com/tag/2hu", "name" => "2hu"}
45 assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
48 test "works with an object that has no tags" do
51 assert Utils.determine_explicit_mentions(object) == []
54 test "works with an object that has only IR tags" do
55 object = %{"tag" => ["2hu"]}
57 assert Utils.determine_explicit_mentions(object) == []
61 describe "make_like_data" do
64 other_user = insert(:user)
65 third_user = insert(:user)
66 [user: user, other_user: other_user, third_user: third_user]
69 test "addresses actor's follower address if the activity is public", %{
71 other_user: other_user,
72 third_user: third_user
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])
78 CommonAPI.post(user, %{
80 "hey @#{other_user.nickname}, @#{third_user.nickname} how about beering together this weekend?"
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
88 test "does not adress actor's follower address if the activity is not public", %{
90 other_user: other_user,
91 third_user: third_user
93 expected_to = Enum.sort([user.ap_id])
94 expected_cc = [third_user.ap_id]
97 CommonAPI.post(user, %{
98 "status" => "@#{other_user.nickname} @#{third_user.nickname} bought a new swimsuit!",
99 "visibility" => "private"
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