1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ActivityExpirationTest do
7 alias Pleroma.ActivityExpiration
10 setup do: clear_config([ActivityExpiration, :enabled])
12 test "finds activities due to be deleted only" do
13 activity = insert(:note_activity)
16 insert(:expiration_in_the_past, %{activity_id: activity.id}) |> Repo.preload(:activity)
18 activity2 = insert(:note_activity)
19 insert(:expiration_in_the_future, %{activity_id: activity2.id})
21 expirations = ActivityExpiration.due_expirations()
23 assert length(expirations) == 1
24 assert hd(expirations) == expiration_due
27 test "denies expirations that don't live long enough" do
28 activity = insert(:note_activity)
29 now = NaiveDateTime.utc_now()
30 assert {:error, _} = ActivityExpiration.create(activity, now)
33 test "deletes an expiration activity" do
34 Pleroma.Config.put([ActivityExpiration, :enabled], true)
35 activity = insert(:note_activity)
39 NaiveDateTime.utc_now(),
46 :expiration_in_the_past,
47 %{activity_id: activity.id, scheduled_at: naive_datetime}
50 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(%Oban.Job{})
52 refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
53 refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)