2019-07-22 12:16:20 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 05:08:45 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-07-22 12:16:20 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.ActivityExpirationTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
alias Pleroma.ActivityExpiration
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2020-03-20 15:33:00 +00:00
|
|
|
setup do: clear_config([ActivityExpiration, :enabled])
|
2019-11-27 10:35:02 +00:00
|
|
|
|
2019-07-22 12:16:20 +00:00
|
|
|
test "finds activities due to be deleted only" do
|
|
|
|
activity = insert(:note_activity)
|
2020-08-12 16:46:47 +00:00
|
|
|
|
|
|
|
expiration_due =
|
|
|
|
insert(:expiration_in_the_past, %{activity_id: activity.id}) |> Repo.preload(:activity)
|
|
|
|
|
2019-07-22 12:16:20 +00:00
|
|
|
activity2 = insert(:note_activity)
|
|
|
|
insert(:expiration_in_the_future, %{activity_id: activity2.id})
|
|
|
|
|
|
|
|
expirations = ActivityExpiration.due_expirations()
|
|
|
|
|
|
|
|
assert length(expirations) == 1
|
|
|
|
assert hd(expirations) == expiration_due
|
|
|
|
end
|
2019-07-23 14:33:45 +00:00
|
|
|
|
|
|
|
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
|
2019-11-27 10:35:02 +00:00
|
|
|
|
|
|
|
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}
|
|
|
|
)
|
|
|
|
|
2020-06-23 12:09:01 +00:00
|
|
|
Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(%Oban.Job{})
|
2019-11-27 10:35:02 +00:00
|
|
|
|
|
|
|
refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
|
|
|
|
refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
|
|
|
|
end
|
2019-07-22 12:16:20 +00:00
|
|
|
end
|