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
15 clear_config([ActivityExpiration, :enabled])
18 test "deletes an expiration activity" do
19 Pleroma.Config.put([ActivityExpiration, :enabled], true)
20 activity = insert(:note_activity)
24 NaiveDateTime.utc_now(),
31 :expiration_in_the_past,
32 %{activity_id: activity.id, scheduled_at: naive_datetime}
35 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
37 refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
38 refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
41 test "works with ActivityExpirationPolicy" do
42 Pleroma.Config.put([ActivityExpiration, :enabled], true)
44 clear_config([:mrf, :policies], Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy)
48 days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
50 {:ok, %{id: id} = activity} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
53 NaiveDateTime.utc_now() |> Timex.shift(days: -days) |> NaiveDateTime.truncate(:second)
56 |> Repo.preload(:expiration)
57 |> Map.get(:expiration)
58 |> Ecto.Changeset.change(%{scheduled_at: past_date})
61 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
63 assert [%{data: %{"type" => "Delete", "deleted_activity_id" => ^id}}] =
64 Pleroma.Repo.all(Pleroma.Activity)
67 describe "delete_activity/1" do
68 test "adds log message if activity isn't find" do
69 assert capture_log([level: :error], fn ->
70 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
71 activity_id: "test-activity"
73 end) =~ "Couldn't delete expired activity: not found activity"
76 test "adds log message if actor isn't find" do
77 assert capture_log([level: :error], fn ->
78 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
79 activity_id: "test-activity"
81 end) =~ "Couldn't delete expired activity: not found activity"