+ 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 == ActivityPub.fetch_latest_follow(follower, followed)
+ 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 activity.data["object"] == follow_activity.data["id"]
+ end
+ end
+