2020-01-23 08:05:08 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-01-23 08:05:08 +00: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
|
|
|
|
|
2020-03-20 15:33:00 +00:00
|
|
|
setup do: clear_config([ScheduledActivity, :enabled])
|
2020-01-23 08:05:08 +00:00
|
|
|
|
|
|
|
test "creates a status from the scheduled activity" do
|
|
|
|
Pleroma.Config.put([ScheduledActivity, :enabled], true)
|
|
|
|
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"}
|
|
|
|
)
|
|
|
|
|
2020-06-23 12:09:01 +00:00
|
|
|
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
|
2020-01-23 08:05:08 +00:00
|
|
|
|
|
|
|
refute Repo.get(ScheduledActivity, scheduled_activity.id)
|
|
|
|
activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
|
2021-01-04 12:38:31 +00:00
|
|
|
assert Pleroma.Object.normalize(activity, fetch: false).data["content"] == "hi"
|
2020-01-23 08:05:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "adds log message if ScheduledActivity isn't find" do
|
|
|
|
Pleroma.Config.put([ScheduledActivity, :enabled], true)
|
|
|
|
|
|
|
|
assert capture_log([level: :error], fn ->
|
2020-06-23 12:09:01 +00:00
|
|
|
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})
|
2020-01-23 08:05:08 +00:00
|
|
|
end) =~ "Couldn't find scheduled activity"
|
|
|
|
end
|
|
|
|
end
|