Purge Rejected Follow requests in daily task (#334)
[akkoma] / test / pleroma / activity / pruner_test.exs
index 312d4f5e493e7f6b1bc37f6a889c3ff80b74e773..e8d4b30aad0725159752f5c2e5feabaf4f274fa5 100644 (file)
@@ -24,4 +24,40 @@ defmodule Pleroma.Activity.PrunerTest do
       refute Activity.get_by_id(old_delete.id)
     end
   end
+
+  describe "prune_stale_follow_requests" do
+    test "it prunes old follow requests" do
+      follower = insert(:user)
+      followee = insert(:user)
+
+      new_follow_request =
+        insert(
+          :follow_activity,
+          follower: follower,
+          followed: followee,
+          state: "reject"
+        )
+
+      old_not_rejected_request =
+        insert(:follow_activity,
+          follower: follower,
+          followed: followee,
+          state: "pending",
+          inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour)
+        )
+
+      old_follow_request =
+        insert(:follow_activity,
+          follower: follower,
+          followed: followee,
+          inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour),
+          state: "reject"
+        )
+
+      Pruner.prune_stale_follow_requests()
+      assert Activity.get_by_id(new_follow_request.id)
+      assert Activity.get_by_id(old_not_rejected_request.id)
+      refute Activity.get_by_id(old_follow_request.id)
+    end
+  end
 end