2020-01-23 01:05:08 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 13:38:50 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-01-23 01:05:08 -07:00
|
|
|
# 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
|
|
|
|
|
2021-02-01 08:22:26 -07:00
|
|
|
setup do: clear_config([ScheduledActivity, :enabled], true)
|
2020-01-23 01:05:08 -07:00
|
|
|
|
|
|
|
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"}
|
|
|
|
)
|
|
|
|
|
2021-02-01 08:22:26 -07:00
|
|
|
{:ok, %{id: activity_id}} =
|
|
|
|
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
|
2020-01-23 01:05:08 -07:00
|
|
|
|
|
|
|
refute Repo.get(ScheduledActivity, scheduled_activity.id)
|
|
|
|
|
2021-02-01 08:22:26 -07:00
|
|
|
object =
|
|
|
|
Pleroma.Activity
|
|
|
|
|> Repo.get(activity_id)
|
|
|
|
|> Pleroma.Object.normalize()
|
|
|
|
|
|
|
|
assert object.data["content"] == "hi"
|
|
|
|
end
|
2020-01-23 01:05:08 -07:00
|
|
|
|
2021-02-01 08:22:26 -07:00
|
|
|
test "error message for non-existent scheduled activity" do
|
2020-01-23 01:05:08 -07:00
|
|
|
assert capture_log([level: :error], fn ->
|
2020-06-23 06:09:01 -06:00
|
|
|
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})
|
2021-02-01 08:22:26 -07:00
|
|
|
end) =~ "Couldn't find scheduled activity: 42"
|
2020-01-23 01:05:08 -07:00
|
|
|
end
|
|
|
|
end
|