2022-12-01 08:00:53 -07:00
|
|
|
defmodule Pleroma.Activity.PrunerTest do
|
|
|
|
use Pleroma.DataCase, async: true
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Activity.Pruner
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2024-02-09 15:26:23 -07:00
|
|
|
describe "prune_transient_activities" do
|
|
|
|
test "it prunes old transient activities" do
|
2022-12-01 08:00:53 -07:00
|
|
|
user = insert(:user)
|
2024-02-09 15:26:23 -07:00
|
|
|
old_time = DateTime.utc_now() |> DateTime.add(-31 * 24, :hour)
|
2022-12-01 08:00:53 -07:00
|
|
|
|
|
|
|
new_delete = insert(:delete_activity, type: "Delete", user: user)
|
|
|
|
|
|
|
|
old_delete =
|
|
|
|
insert(:delete_activity,
|
|
|
|
user: user,
|
2024-02-09 15:26:23 -07:00
|
|
|
inserted_at: old_time
|
2022-12-01 08:00:53 -07:00
|
|
|
)
|
|
|
|
|
2024-02-09 15:26:23 -07:00
|
|
|
new_update = insert(:update_activity, type: "Update", user: user)
|
|
|
|
|
|
|
|
old_update =
|
|
|
|
insert(:update_activity,
|
|
|
|
type: "Update",
|
|
|
|
user: user,
|
|
|
|
inserted_at: old_time
|
|
|
|
)
|
|
|
|
|
|
|
|
new_undo = insert(:undo_activity)
|
|
|
|
|
|
|
|
old_undo = insert(:undo_activity, inserted_at: old_time)
|
|
|
|
|
|
|
|
new_remove = insert(:remove_activity)
|
|
|
|
|
|
|
|
old_remove = insert(:remove_activity, inserted_at: old_time)
|
|
|
|
|
2022-12-01 08:00:53 -07:00
|
|
|
Pruner.prune_deletes()
|
2024-02-09 15:26:23 -07:00
|
|
|
Pruner.prune_updates()
|
|
|
|
Pruner.prune_undos()
|
|
|
|
Pruner.prune_removes()
|
|
|
|
|
2022-12-01 08:00:53 -07:00
|
|
|
assert Activity.get_by_id(new_delete.id)
|
|
|
|
refute Activity.get_by_id(old_delete.id)
|
2024-02-09 15:26:23 -07:00
|
|
|
|
|
|
|
assert Activity.get_by_id(new_update.id)
|
|
|
|
refute Activity.get_by_id(old_update.id)
|
|
|
|
|
|
|
|
assert Activity.get_by_id(new_undo.id)
|
|
|
|
refute Activity.get_by_id(old_undo.id)
|
|
|
|
|
|
|
|
assert Activity.get_by_id(new_remove.id)
|
|
|
|
refute Activity.get_by_id(old_remove.id)
|
2022-12-01 08:00:53 -07:00
|
|
|
end
|
|
|
|
end
|
2022-12-03 16:17:43 -07:00
|
|
|
|
|
|
|
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
|
2022-12-01 08:00:53 -07:00
|
|
|
end
|