Merge branch 'develop' into global-status-expiration
[akkoma] / test / activity_expiration_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.ActivityExpirationTest do
6 use Pleroma.DataCase
7 alias Pleroma.ActivityExpiration
8 import Pleroma.Factory
9
10 setup do: clear_config([ActivityExpiration, :enabled])
11
12 test "finds activities due to be deleted only" do
13 activity = insert(:note_activity)
14 expiration_due = insert(:expiration_in_the_past, %{activity_id: activity.id})
15 activity2 = insert(:note_activity)
16 insert(:expiration_in_the_future, %{activity_id: activity2.id})
17
18 expirations = ActivityExpiration.due_expirations()
19
20 assert length(expirations) == 1
21 assert hd(expirations) == expiration_due
22 end
23
24 test "denies expirations that don't live long enough" do
25 activity = insert(:note_activity)
26 now = NaiveDateTime.utc_now()
27 assert {:error, _} = ActivityExpiration.create(activity, now)
28 end
29
30 test "deletes an expiration activity" do
31 Pleroma.Config.put([ActivityExpiration, :enabled], true)
32 activity = insert(:note_activity)
33
34 naive_datetime =
35 NaiveDateTime.add(
36 NaiveDateTime.utc_now(),
37 -:timer.minutes(2),
38 :millisecond
39 )
40
41 expiration =
42 insert(
43 :expiration_in_the_past,
44 %{activity_id: activity.id, scheduled_at: naive_datetime}
45 )
46
47 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
48
49 refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
50 refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
51 end
52 end