2020-08-22 17:46:01 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-08-22 17:46:01 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.PurgeExpiredActivityTest do
|
|
|
|
use Pleroma.DataCase, async: true
|
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
alias Pleroma.Workers.PurgeExpiredActivity
|
|
|
|
|
2020-09-08 12:11:18 +00:00
|
|
|
test "enqueue job" do
|
2020-08-22 17:46:01 +00:00
|
|
|
activity = insert(:note_activity)
|
|
|
|
|
2020-09-08 12:11:18 +00:00
|
|
|
assert {:ok, _} =
|
2020-08-22 17:46:01 +00:00
|
|
|
PurgeExpiredActivity.enqueue(%{
|
|
|
|
activity_id: activity.id,
|
2020-09-08 12:11:18 +00:00
|
|
|
expires_at: DateTime.add(DateTime.utc_now(), 3601)
|
2020-08-22 17:46:01 +00:00
|
|
|
})
|
|
|
|
|
2020-09-08 12:11:18 +00:00
|
|
|
assert_enqueued(
|
2020-08-22 17:46:01 +00:00
|
|
|
worker: Pleroma.Workers.PurgeExpiredActivity,
|
|
|
|
args: %{activity_id: activity.id}
|
|
|
|
)
|
2020-09-08 12:11:18 +00:00
|
|
|
|
|
|
|
assert {:ok, _} =
|
|
|
|
perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
|
|
|
|
|
|
|
|
assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
2020-08-22 17:46:01 +00:00
|
|
|
end
|
|
|
|
|
2020-09-08 12:11:18 +00:00
|
|
|
test "error if user was not found" do
|
2020-08-22 17:46:01 +00:00
|
|
|
activity = insert(:note_activity)
|
|
|
|
|
|
|
|
assert {:ok, _} =
|
|
|
|
PurgeExpiredActivity.enqueue(%{
|
|
|
|
activity_id: activity.id,
|
|
|
|
expires_at: DateTime.add(DateTime.utc_now(), 3601)
|
|
|
|
})
|
|
|
|
|
2020-09-08 12:11:18 +00:00
|
|
|
user = Pleroma.User.get_by_ap_id(activity.actor)
|
|
|
|
Pleroma.Repo.delete(user)
|
2020-08-22 17:46:01 +00:00
|
|
|
|
2020-09-08 12:11:18 +00:00
|
|
|
assert {:error, :user_not_found} =
|
2020-08-22 17:46:01 +00:00
|
|
|
perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
|
2020-09-08 12:11:18 +00:00
|
|
|
end
|
2020-08-22 17:46:01 +00:00
|
|
|
|
2020-09-08 12:11:18 +00:00
|
|
|
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"})
|
2020-08-22 17:46:01 +00:00
|
|
|
end
|
2022-11-13 23:55:51 +00:00
|
|
|
|
|
|
|
test "has a timeout" do
|
|
|
|
clear_config([:workers, :timeout, :activity_expiration], 50)
|
|
|
|
assert Pleroma.Workers.PurgeExpiredActivity.timeout(%Oban.Job{}) == 50
|
|
|
|
end
|
2020-08-22 17:46:01 +00:00
|
|
|
end
|