akkoma/test/pleroma/workers/scheduled_activity_worker_test.exs
floatingghost c1127e321b Add configurable timeline per oban job (#273)
Heavily inspired by https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3777

Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk>
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/273
2022-11-13 23:55:51 +00:00

58 lines
1.6 KiB
Elixir

# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.ScheduledActivityWorkerTest do
use Pleroma.DataCase
alias Pleroma.ScheduledActivity
alias Pleroma.Workers.ScheduledActivityWorker
import Pleroma.Factory
import ExUnit.CaptureLog
setup do: clear_config([ScheduledActivity, :enabled], true)
test "creates a status from the scheduled activity" do
user = insert(:user)
naive_datetime =
NaiveDateTime.add(
NaiveDateTime.utc_now(),
-:timer.minutes(2),
:millisecond
)
scheduled_activity =
insert(
:scheduled_activity,
scheduled_at: naive_datetime,
user: user,
params: %{status: "hi"}
)
{:ok, %{id: activity_id}} =
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
refute Repo.get(ScheduledActivity, scheduled_activity.id)
object =
Pleroma.Activity
|> Repo.get(activity_id)
|> Pleroma.Object.normalize()
assert object.data["content"] == "hi"
end
test "error message for non-existent scheduled activity" do
assert capture_log([level: :error], fn ->
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})
end) =~ "Couldn't find scheduled activity: 42"
end
test "has a timeout" do
clear_config([:workers, :timeout, :scheduled_activities], :timer.minutes(5))
assert ScheduledActivityWorker.timeout(nil) == :timer.minutes(5)
end
end