describe "create activities" do
test "removes doubled 'to' recipients" do
+ user = insert(:user)
+
{:ok, activity} =
ActivityPub.create(%{
to: ["user1", "user1", "user2"],
- actor: %User{ap_id: "1"},
+ actor: user,
context: "",
object: %{}
})
assert activity.data["to"] == ["user1", "user2"]
- assert activity.actor == "1"
+ assert activity.actor == user.ap_id
assert activity.recipients == ["user1", "user2"]
end
end
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
end
end
+ describe "unannouncing an object" do
+ test "unannouncing a previously announced object" do
+ note_activity = insert(:note_activity)
+ object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+ user = insert(:user)
+
+ # Unannouncing an object that is not announced does nothing
+ # {:ok, object} = ActivityPub.unannounce(user, object)
+ # assert object.data["announcement_count"] == 0
+
+ {:ok, announce_activity, object} = ActivityPub.announce(user, object)
+ assert object.data["announcement_count"] == 1
+
+ {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object)
+ assert object.data["announcement_count"] == 0
+
+ assert unannounce_activity.data["to"] == [
+ User.ap_followers(user),
+ announce_activity.data["actor"]
+ ]
+
+ assert unannounce_activity.data["type"] == "Undo"
+ assert unannounce_activity.data["object"] == announce_activity.data
+ assert unannounce_activity.data["actor"] == user.ap_id
+ assert unannounce_activity.data["context"] == announce_activity.data["context"]
+
+ assert Repo.get(Activity, announce_activity.id) == nil
+ end
+ end
+
describe "uploading files" do
test "copies the file to the configured folder" do
file = %Plug.Upload{
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
end
end
+ test "it can fetch plume articles" do
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id(
+ "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
+ )
+
+ assert object
+ end
+
describe "update" do
test "it creates an update activity with the new user data" do
user = insert(:user)
end
end
+ test "it can fetch peertube videos" do
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id(
+ "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
+ )
+
+ assert object
+ end
+
def data_uri do
File.read!("test/fixtures/avatar_data_uri")
end