Merge branch 'delete_orphaned_activities' into develop
[akkoma] / test / pleroma / activity / pruner_test.exs
1 defmodule Pleroma.Activity.PrunerTest do
2 use Pleroma.DataCase, async: true
3
4 alias Pleroma.Activity
5 alias Pleroma.Activity.Pruner
6
7 import Pleroma.Factory
8
9 describe "prune_deletes" do
10 test "it prunes old delete objects" do
11 user = insert(:user)
12
13 new_delete = insert(:delete_activity, type: "Delete", user: user)
14
15 old_delete =
16 insert(:delete_activity,
17 type: "Delete",
18 user: user,
19 inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour)
20 )
21
22 Pruner.prune_deletes()
23 assert Activity.get_by_id(new_delete.id)
24 refute Activity.get_by_id(old_delete.id)
25 end
26 end
27
28 describe "prune_stale_follow_requests" do
29 test "it prunes old follow requests" do
30 follower = insert(:user)
31 followee = insert(:user)
32
33 new_follow_request =
34 insert(
35 :follow_activity,
36 follower: follower,
37 followed: followee,
38 state: "reject"
39 )
40
41 old_not_rejected_request =
42 insert(:follow_activity,
43 follower: follower,
44 followed: followee,
45 state: "pending",
46 inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour)
47 )
48
49 old_follow_request =
50 insert(:follow_activity,
51 follower: follower,
52 followed: followee,
53 inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour),
54 state: "reject"
55 )
56
57 Pruner.prune_stale_follow_requests()
58 assert Activity.get_by_id(new_follow_request.id)
59 assert Activity.get_by_id(old_not_rejected_request.id)
60 refute Activity.get_by_id(old_follow_request.id)
61 end
62 end
63 end