X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fworkers%2Fcron%2Fpurge_expired_activities_worker_test.exs;h=b1db59fdf8876eb89ae3d64a715711af70365b69;hb=1d0804b49f56fe722b12f83269d98acfdee7ac77;hp=07980bcd0b889bafdb9064c21d02efd363624212;hpb=2b821036c4bd84cee51c9fcace5a4b3764c3bba1;p=akkoma
diff --git a/test/workers/cron/purge_expired_activities_worker_test.exs b/test/workers/cron/purge_expired_activities_worker_test.exs
index 07980bcd0..b1db59fdf 100644
--- a/test/workers/cron/purge_expired_activities_worker_test.exs
+++ b/test/workers/cron/purge_expired_activities_worker_test.exs
@@ -1,13 +1,19 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.Cron.PurgeExpiredActivitiesWorkerTest do
use Pleroma.DataCase
+
alias Pleroma.ActivityExpiration
+ alias Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker
+
import Pleroma.Factory
+ import ExUnit.CaptureLog
- clear_config([ActivityExpiration, :enabled])
+ setup do
+ clear_config([ActivityExpiration, :enabled])
+ end
test "deletes an expiration activity" do
Pleroma.Config.put([ActivityExpiration, :enabled], true)
@@ -31,4 +37,48 @@ defmodule Pleroma.Workers.Cron.PurgeExpiredActivitiesWorkerTest do
refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
end
+
+ test "works with ActivityExpirationPolicy" do
+ Pleroma.Config.put([ActivityExpiration, :enabled], true)
+
+ clear_config([:mrf, :policies], Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy)
+
+ user = insert(:user)
+
+ days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
+
+ {:ok, %{id: id} = activity} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
+
+ past_date =
+ NaiveDateTime.utc_now() |> Timex.shift(days: -days) |> NaiveDateTime.truncate(:second)
+
+ activity
+ |> Repo.preload(:expiration)
+ |> Map.get(:expiration)
+ |> Ecto.Changeset.change(%{scheduled_at: past_date})
+ |> Repo.update!()
+
+ Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
+
+ assert [%{data: %{"type" => "Delete", "deleted_activity_id" => ^id}}] =
+ Pleroma.Repo.all(Pleroma.Activity)
+ end
+
+ describe "delete_activity/1" do
+ test "adds log message if activity isn't find" do
+ assert capture_log([level: :error], fn ->
+ PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
+ activity_id: "test-activity"
+ })
+ end) =~ "Couldn't delete expired activity: not found activity"
+ end
+
+ test "adds log message if actor isn't find" do
+ assert capture_log([level: :error], fn ->
+ PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
+ activity_id: "test-activity"
+ })
+ end) =~ "Couldn't delete expired activity: not found activity"
+ end
+ end
end