logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

purge_expired_activity_test.exs (1816B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Workers.PurgeExpiredActivityTest do
  5. use Pleroma.DataCase, async: true
  6. use Oban.Testing, repo: Pleroma.Repo
  7. import Pleroma.Factory
  8. alias Pleroma.Workers.PurgeExpiredActivity
  9. test "enqueue job" do
  10. activity = insert(:note_activity)
  11. assert {:ok, _} =
  12. PurgeExpiredActivity.enqueue(%{
  13. activity_id: activity.id,
  14. expires_at: DateTime.add(DateTime.utc_now(), 3601)
  15. })
  16. assert_enqueued(
  17. worker: Pleroma.Workers.PurgeExpiredActivity,
  18. args: %{activity_id: activity.id}
  19. )
  20. assert {:ok, _} =
  21. perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
  22. assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
  23. end
  24. test "error if user was not found" do
  25. activity = insert(:note_activity)
  26. assert {:ok, _} =
  27. PurgeExpiredActivity.enqueue(%{
  28. activity_id: activity.id,
  29. expires_at: DateTime.add(DateTime.utc_now(), 3601)
  30. })
  31. user = Pleroma.User.get_by_ap_id(activity.actor)
  32. Pleroma.Repo.delete(user)
  33. assert {:error, :user_not_found} =
  34. perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
  35. end
  36. test "error if actiivity was not found" do
  37. assert {:ok, _} =
  38. PurgeExpiredActivity.enqueue(%{
  39. activity_id: "some_id",
  40. expires_at: DateTime.add(DateTime.utc_now(), 3601)
  41. })
  42. assert {:error, :activity_not_found} =
  43. perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: "some_if"})
  44. end
  45. end