2020-08-22 11:46:01 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 13:38:50 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-08-22 11:46:01 -06: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 06:11:18 -06:00
|
|
|
test "enqueue job" do
|
2020-08-22 11:46:01 -06:00
|
|
|
activity = insert(:note_activity)
|
|
|
|
|
2020-09-08 06:11:18 -06:00
|
|
|
assert {:ok, _} =
|
2020-08-22 11:46:01 -06:00
|
|
|
PurgeExpiredActivity.enqueue(%{
|
|
|
|
activity_id: activity.id,
|
2020-09-08 06:11:18 -06:00
|
|
|
expires_at: DateTime.add(DateTime.utc_now(), 3601)
|
2020-08-22 11:46:01 -06:00
|
|
|
})
|
|
|
|
|
2020-09-08 06:11:18 -06:00
|
|
|
assert_enqueued(
|
2020-08-22 11:46:01 -06:00
|
|
|
worker: Pleroma.Workers.PurgeExpiredActivity,
|
|
|
|
args: %{activity_id: activity.id}
|
|
|
|
)
|
2020-09-08 06:11:18 -06: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 11:46:01 -06:00
|
|
|
end
|
|
|
|
|
2020-09-08 06:11:18 -06:00
|
|
|
test "error if user was not found" do
|
2020-08-22 11:46:01 -06:00
|
|
|
activity = insert(:note_activity)
|
|
|
|
|
|
|
|
assert {:ok, _} =
|
|
|
|
PurgeExpiredActivity.enqueue(%{
|
|
|
|
activity_id: activity.id,
|
|
|
|
expires_at: DateTime.add(DateTime.utc_now(), 3601)
|
|
|
|
})
|
|
|
|
|
2020-09-08 06:11:18 -06:00
|
|
|
user = Pleroma.User.get_by_ap_id(activity.actor)
|
|
|
|
Pleroma.Repo.delete(user)
|
2020-08-22 11:46:01 -06:00
|
|
|
|
2020-09-08 06:11:18 -06:00
|
|
|
assert {:error, :user_not_found} =
|
2020-08-22 11:46:01 -06:00
|
|
|
perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
|
2020-09-08 06:11:18 -06:00
|
|
|
end
|
2020-08-22 11:46:01 -06:00
|
|
|
|
2020-09-08 06:11:18 -06: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 11:46:01 -06:00
|
|
|
end
|
|
|
|
end
|