1 defmodule Pleroma.Web.ActivityPub.UtilsTest do
3 alias Pleroma.Web.ActivityPub.Utils
4 alias Pleroma.Web.CommonAPI
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
108 describe "fetch_ordered_collection" do
111 test "fetches the first OrderedCollectionPage when an OrderedCollection is encountered" do
113 %{method: :get, url: "http://mastodon.com/outbox"} ->
114 json(%{"type" => "OrderedCollection", "first" => "http://mastodon.com/outbox?page=true"})
116 %{method: :get, url: "http://mastodon.com/outbox?page=true"} ->
117 json(%{"type" => "OrderedCollectionPage", "orderedItems" => ["ok"]})
120 assert Utils.fetch_ordered_collection("http://mastodon.com/outbox", 1) == ["ok"]
123 test "fetches several pages in the right order one after another, but only the specified amount" do
125 %{method: :get, url: "http://example.com/outbox"} ->
127 "type" => "OrderedCollectionPage",
128 "orderedItems" => [0],
129 "next" => "http://example.com/outbox?page=1"
132 %{method: :get, url: "http://example.com/outbox?page=1"} ->
134 "type" => "OrderedCollectionPage",
135 "orderedItems" => [1],
136 "next" => "http://example.com/outbox?page=2"
139 %{method: :get, url: "http://example.com/outbox?page=2"} ->
140 json(%{"type" => "OrderedCollectionPage", "orderedItems" => [2]})
143 assert Utils.fetch_ordered_collection("http://example.com/outbox", 0) == [0]
144 assert Utils.fetch_ordered_collection("http://example.com/outbox", 1) == [0, 1]
147 test "returns an error if the url doesn't have an OrderedCollection/Page" do
149 %{method: :get, url: "http://example.com/not-an-outbox"} ->
150 json(%{"type" => "NotAnOutbox"})
153 assert {:error, _} = Utils.fetch_ordered_collection("http://example.com/not-an-outbox", 1)
156 test "returns the what was collected if there are less pages than specified" do
158 %{method: :get, url: "http://example.com/outbox"} ->
160 "type" => "OrderedCollectionPage",
161 "orderedItems" => [0],
162 "next" => "http://example.com/outbox?page=1"
165 %{method: :get, url: "http://example.com/outbox?page=1"} ->
166 json(%{"type" => "OrderedCollectionPage", "orderedItems" => [1]})
169 assert Utils.fetch_ordered_collection("http://example.com/outbox", 5) == [0, 1]