use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.CommonAPI
alias Pleroma.{Activity, Object, User}
alias Pleroma.Builders.ActivityBuilder
test "doesn't return blocked activities" do
activity_one = insert(:note_activity)
activity_two = insert(:note_activity)
+ activity_three = insert(:note_activity)
user = insert(:user)
+ booster = insert(:user)
{:ok, user} = User.block(user, %{ap_id: activity_one.data["actor"]})
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
refute Enum.member?(activities, activity_one)
{:ok, user} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
+ assert Enum.member?(activities, activity_one)
+
+ {:ok, user} = User.block(user, %{ap_id: activity_three.data["actor"]})
+ {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
+ %Activity{} = boost_activity = Activity.get_create_activity_by_object_ap_id(id)
+ activity_three = Repo.get(Activity, activity_three.id)
+
+ activities = ActivityPub.fetch_activities([], %{"blocking_user" => user})
+
+ assert Enum.member?(activities, activity_two)
+ refute Enum.member?(activities, activity_three)
+ refute Enum.member?(activities, boost_activity)
assert Enum.member?(activities, activity_one)
activities = ActivityPub.fetch_activities([], %{"blocking_user" => nil})
assert Enum.member?(activities, activity_two)
+ assert Enum.member?(activities, activity_three)
+ assert Enum.member?(activities, boost_activity)
assert Enum.member?(activities, activity_one)
end
describe "public fetch activities" do
+ test "doesn't retrieve unlisted activities" do
+ user = insert(:user)
+
+ {:ok, unlisted_activity} =
+ CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"})
+
+ {:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"})
+
+ [activity] = ActivityPub.fetch_public_activities()
+
+ assert activity == listed_activity
+ end
+
test "retrieves public activities" do
_activities = ActivityPub.fetch_public_activities()
{:ok, like_activity, object} = ActivityPub.like(user, object)
assert object.data["like_count"] == 1
- {:ok, object} = ActivityPub.unlike(user, object)
+ {:ok, _, _, object} = ActivityPub.unlike(user, object)
assert object.data["like_count"] == 0
assert Repo.get(Activity, like_activity.id) == nil
{:ok, announce_activity, object} = ActivityPub.announce(user, object)
assert object.data["announcement_count"] == 1
- {:ok, unannounce_activity, activity, object} = ActivityPub.unannounce(user, object)
+ {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object)
assert object.data["announcement_count"] == 0
- assert activity == announce_activity
-
assert unannounce_activity.data["to"] == [
User.ap_followers(user),
announce_activity.data["actor"]
assert activity.data["type"] == "Undo"
assert activity.data["actor"] == follower.ap_id
- assert activity.data["object"] == follow_activity.data["id"]
+
+ assert is_map(activity.data["object"])
+ assert activity.data["object"]["type"] == "Follow"
+ assert activity.data["object"]["object"] == followed.ap_id
+ assert activity.data["object"]["id"] == follow_activity.data["id"]
+ end
+ end
+
+ describe "blocking / unblocking" do
+ test "creates a block activity" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, activity} = ActivityPub.block(blocker, blocked)
+
+ assert activity.data["type"] == "Block"
+ assert activity.data["actor"] == blocker.ap_id
+ assert activity.data["object"] == blocked.ap_id
+ end
+
+ test "creates an undo activity for the last block" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, block_activity} = ActivityPub.block(blocker, blocked)
+ {:ok, activity} = ActivityPub.unblock(blocker, blocked)
+
+ assert activity.data["type"] == "Undo"
+ assert activity.data["actor"] == blocker.ap_id
+
+ assert is_map(activity.data["object"])
+ assert activity.data["object"]["type"] == "Block"
+ assert activity.data["object"]["object"] == blocked.ap_id
+ assert activity.data["object"]["id"] == block_activity.data["id"]
end
end