logo

pleroma

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

scheduled_activity_worker_test.exs (1516B)


  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.ScheduledActivityWorkerTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.ScheduledActivity
  7. alias Pleroma.Workers.ScheduledActivityWorker
  8. import Pleroma.Factory
  9. import ExUnit.CaptureLog
  10. setup do: clear_config([ScheduledActivity, :enabled])
  11. test "creates a status from the scheduled activity" do
  12. Pleroma.Config.put([ScheduledActivity, :enabled], true)
  13. user = insert(:user)
  14. naive_datetime =
  15. NaiveDateTime.add(
  16. NaiveDateTime.utc_now(),
  17. -:timer.minutes(2),
  18. :millisecond
  19. )
  20. scheduled_activity =
  21. insert(
  22. :scheduled_activity,
  23. scheduled_at: naive_datetime,
  24. user: user,
  25. params: %{status: "hi"}
  26. )
  27. ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
  28. refute Repo.get(ScheduledActivity, scheduled_activity.id)
  29. activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
  30. assert Pleroma.Object.normalize(activity).data["content"] == "hi"
  31. end
  32. test "adds log message if ScheduledActivity isn't find" do
  33. Pleroma.Config.put([ScheduledActivity, :enabled], true)
  34. assert capture_log([level: :error], fn ->
  35. ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})
  36. end) =~ "Couldn't find scheduled activity"
  37. end
  38. end