X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Factivity_expiration_test.exs;h=e899d45093660d001675e69f8068004c8299a838;hb=d191b0942f64a32a2bf450318fac85981aa17c83;hp=20566a186b72287150c4abb0d700a4daf7508482;hpb=666514194a325e2463c05bae516b89d7c5f59316;p=akkoma
diff --git a/test/activity_expiration_test.exs b/test/activity_expiration_test.exs
index 20566a186..e899d4509 100644
--- a/test/activity_expiration_test.exs
+++ b/test/activity_expiration_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ActivityExpirationTest do
@@ -7,6 +7,8 @@ defmodule Pleroma.ActivityExpirationTest do
alias Pleroma.ActivityExpiration
import Pleroma.Factory
+ setup do: clear_config([ActivityExpiration, :enabled])
+
test "finds activities due to be deleted only" do
activity = insert(:note_activity)
expiration_due = insert(:expiration_in_the_past, %{activity_id: activity.id})
@@ -18,4 +20,33 @@ defmodule Pleroma.ActivityExpirationTest do
assert length(expirations) == 1
assert hd(expirations) == expiration_due
end
+
+ test "denies expirations that don't live long enough" do
+ activity = insert(:note_activity)
+ now = NaiveDateTime.utc_now()
+ assert {:error, _} = ActivityExpiration.create(activity, now)
+ end
+
+ test "deletes an expiration activity" do
+ Pleroma.Config.put([ActivityExpiration, :enabled], true)
+ activity = insert(:note_activity)
+
+ naive_datetime =
+ NaiveDateTime.add(
+ NaiveDateTime.utc_now(),
+ -:timer.minutes(2),
+ :millisecond
+ )
+
+ expiration =
+ insert(
+ :expiration_in_the_past,
+ %{activity_id: activity.id, scheduled_at: naive_datetime}
+ )
+
+ Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
+
+ refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
+ refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
+ end
end