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])
16 clear_config([:instance, :rewrite_policy])
19 test "deletes an expiration activity" do
20 Pleroma.Config.put([ActivityExpiration, :enabled], true)
21 activity = insert(:note_activity)
25 NaiveDateTime.utc_now(),
32 :expiration_in_the_past,
33 %{activity_id: activity.id, scheduled_at: naive_datetime}
36 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
38 refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
39 refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
42 test "works with ActivityExpirationPolicy" do
43 Pleroma.Config.put([ActivityExpiration, :enabled], true)
46 [:instance, :rewrite_policy],
47 Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
52 days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
54 {:ok, %{id: id} = activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
57 NaiveDateTime.utc_now() |> Timex.shift(days: -days) |> NaiveDateTime.truncate(:second)
60 |> Repo.preload(:expiration)
61 |> Map.get(:expiration)
62 |> Ecto.Changeset.change(%{scheduled_at: past_date})
65 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
67 assert [%{data: %{"type" => "Delete", "deleted_activity_id" => ^id}}] =
68 Pleroma.Repo.all(Pleroma.Activity)
71 describe "delete_activity/1" do
72 test "adds log message if activity isn't find" do
73 assert capture_log([level: :error], fn ->
74 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
75 activity_id: "test-activity"
77 end) =~ "Couldn't delete expired activity: not found activity"
80 test "adds log message if actor isn't find" do
81 assert capture_log([level: :error], fn ->
82 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
83 activity_id: "test-activity"
85 end) =~ "Couldn't delete expired activity: not found activity"