honkoma/test/workers/purge_expired_activity_test...

60 lines
1.8 KiB
Elixir
Raw Normal View History

2020-08-22 17:46:01 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# 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
test "enqueue job" do
2020-08-22 17:46:01 +00:00
activity = insert(:note_activity)
assert {:ok, _} =
2020-08-22 17:46:01 +00:00
PurgeExpiredActivity.enqueue(%{
activity_id: activity.id,
expires_at: DateTime.add(DateTime.utc_now(), 3601)
2020-08-22 17:46:01 +00:00
})
assert_enqueued(
2020-08-22 17:46:01 +00:00
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)
2020-08-22 17:46:01 +00:00
end
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)
})
user = Pleroma.User.get_by_ap_id(activity.actor)
Pleroma.Repo.delete(user)
2020-08-22 17:46:01 +00:00
assert {:error, :user_not_found} =
2020-08-22 17:46:01 +00:00
perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
end
2020-08-22 17:46:01 +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
end