| {:error, :expired_activities_disabled}
| {:error, :expiration_too_close}
def enqueue(args) do
- with true <- enabled?(),
- args when is_map(args) <- validate_expires_at(args) do
+ with true <- enabled?() do
{scheduled_at, args} = Map.pop(args, :expires_at)
args
end
end
- defp validate_expires_at(%{validate: false} = args), do: Map.delete(args, :validate)
-
- defp validate_expires_at(args) do
- if expires_late_enough?(args[:expires_at]) do
- args
- else
- {:error, :expiration_too_close}
- end
- end
-
defp find_activity(id) do
with nil <- Activity.get_by_id_with_object(id) do
{:error, :activity_not_found}
alias Pleroma.Workers.PurgeExpiredActivity
- test "denies expirations that don't live long enough" do
+ test "enqueue job" do
activity = insert(:note_activity)
- assert {:error, :expiration_too_close} =
+ assert {:ok, _} =
PurgeExpiredActivity.enqueue(%{
activity_id: activity.id,
- expires_at: DateTime.utc_now()
+ expires_at: DateTime.add(DateTime.utc_now(), 3601)
})
- refute_enqueued(
+ assert_enqueued(
worker: Pleroma.Workers.PurgeExpiredActivity,
args: %{activity_id: activity.id}
)
+
+ assert {:ok, _} =
+ perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
+
+ assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
end
- test "enqueue job" do
+ test "error if user was not found" do
activity = insert(:note_activity)
assert {:ok, _} =
expires_at: DateTime.add(DateTime.utc_now(), 3601)
})
- assert_enqueued(
- worker: Pleroma.Workers.PurgeExpiredActivity,
- args: %{activity_id: activity.id}
- )
+ user = Pleroma.User.get_by_ap_id(activity.actor)
+ Pleroma.Repo.delete(user)
- assert {:ok, _} =
+ assert {:error, :user_not_found} =
perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
+ end
- assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
+ test "error if actiivity was not found" do
+ assert {:ok, _} =
+ PurgeExpiredActivity.enqueue(%{
+ activity_id: "some_id",
+ expires_at: DateTime.add(DateTime.utc_now(), 3601)
+ })
+
+ assert {:error, :activity_not_found} =
+ perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: "some_if"})
end
end