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.Workers.Cron.PurgeExpiredActivitiesWorkerTest do
8 alias Pleroma.ActivityExpiration
9 alias Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker
11 import Pleroma.Factory
12 import ExUnit.CaptureLog
14 clear_config([ActivityExpiration, :enabled])
15 clear_config([:instance, :rewrite_policy])
17 test "deletes an expiration activity" do
18 Pleroma.Config.put([ActivityExpiration, :enabled], true)
19 activity = insert(:note_activity)
23 NaiveDateTime.utc_now(),
30 :expiration_in_the_past,
31 %{activity_id: activity.id, scheduled_at: naive_datetime}
34 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
36 refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
37 refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
40 test "works with ActivityExpirationPolicy" do
41 Pleroma.Config.put([ActivityExpiration, :enabled], true)
44 [:instance, :rewrite_policy],
45 Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
50 days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
52 {:ok, %{id: id} = activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
55 NaiveDateTime.utc_now() |> Timex.shift(days: -days) |> NaiveDateTime.truncate(:second)
58 |> Repo.preload(:expiration)
59 |> Map.get(:expiration)
60 |> Ecto.Changeset.change(%{scheduled_at: past_date})
63 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
65 assert [%{data: %{"type" => "Delete", "deleted_activity_id" => ^id}}] =
66 Pleroma.Repo.all(Pleroma.Activity)
69 describe "delete_activity/1" do
70 test "adds log message if activity isn't find" do
71 assert capture_log([level: :error], fn ->
72 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
73 activity_id: "test-activity"
75 end) =~ "Couldn't delete expired activity: not found activity"
78 test "adds log message if actor isn't find" do
79 assert capture_log([level: :error], fn ->
80 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
81 activity_id: "test-activity"
83 end) =~ "Couldn't delete expired activity: not found activity"