+ describe "fetch the latest Follow" do
+ test "fetches the latest Follow activity" do
+ %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
+ follower = Repo.get_by(User, ap_id: activity.data["actor"])
+ followed = Repo.get_by(User, ap_id: activity.data["object"])
+
+ assert activity == Utils.fetch_latest_follow(follower, followed)
+ end
+ end
+
+ describe "fetching an object" do
+ test "it fetches an object" do
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} =
+ ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert [attachment] = object.data["attachment"]
+ assert is_list(attachment["url"])
+
+ assert object == object_again
+ end
+
+ test "it works with objects only available via Ostatus" do
+ {:ok, object} = ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
+ assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} =
+ ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
+
+ assert object == object_again
+ end
+
+ test "it correctly stitches up conversations between ostatus and ap" do
+ last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
+ {:ok, object} = ActivityPub.fetch_object_from_id(last)
+
+ object = Object.get_by_ap_id(object.data["inReplyTo"])
+ assert object
+ end
+ end
+
+ describe "following / unfollowing" do
+ test "creates a follow activity" do
+ follower = insert(:user)
+ followed = insert(:user)
+
+ {:ok, activity} = ActivityPub.follow(follower, followed)
+ assert activity.data["type"] == "Follow"
+ assert activity.data["actor"] == follower.ap_id
+ assert activity.data["object"] == followed.ap_id
+ end
+
+ test "creates an undo activity for the last follow" do
+ follower = insert(:user)
+ followed = insert(:user)
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, followed)
+ {:ok, activity} = ActivityPub.unfollow(follower, followed)
+
+ assert activity.data["type"] == "Undo"
+ assert activity.data["actor"] == follower.ap_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
+
+ describe "deletion" do
+ test "it creates a delete activity and deletes the original object" do
+ note = insert(:note_activity)
+ object = Object.get_by_ap_id(note.data["object"]["id"])
+ {:ok, delete} = ActivityPub.delete(object)
+
+ assert delete.data["type"] == "Delete"
+ assert delete.data["actor"] == note.data["actor"]
+ assert delete.data["object"] == note.data["object"]["id"]
+
+ assert Repo.get(Activity, delete.id) != nil
+
+ assert Repo.get(Object, object.id) == nil
+ 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)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+ user_data = Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user})
+
+ {:ok, update} =
+ ActivityPub.update(%{
+ actor: user_data["id"],
+ to: [user.follower_address],
+ cc: [],
+ object: user_data
+ })
+
+ assert update.data["actor"] == user.ap_id
+ assert update.data["to"] == [user.follower_address]
+ assert update.data["object"]["id"] == user_data["id"]
+ assert update.data["object"]["type"] == user_data["type"]
+ end
+ end
+