total rebase
[anni] / test / pleroma / workers / scheduled_activity_worker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.ScheduledActivityWorkerTest do
6   use Pleroma.DataCase
7
8   alias Pleroma.ScheduledActivity
9   alias Pleroma.Workers.ScheduledActivityWorker
10
11   import Pleroma.Factory
12   import ExUnit.CaptureLog
13
14   setup do: clear_config([ScheduledActivity, :enabled], true)
15
16   test "creates a status from the scheduled activity" do
17     user = insert(:user)
18
19     naive_datetime =
20       NaiveDateTime.add(
21         NaiveDateTime.utc_now(),
22         -:timer.minutes(2),
23         :millisecond
24       )
25
26     scheduled_activity =
27       insert(
28         :scheduled_activity,
29         scheduled_at: naive_datetime,
30         user: user,
31         params: %{status: "hi"}
32       )
33
34     {:ok, %{id: activity_id}} =
35       ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
36
37     refute Repo.get(ScheduledActivity, scheduled_activity.id)
38
39     object =
40       Pleroma.Activity
41       |> Repo.get(activity_id)
42       |> Pleroma.Object.normalize()
43
44     assert object.data["content"] == "hi"
45   end
46
47   test "error message for non-existent scheduled activity" do
48     assert capture_log([level: :error], fn ->
49              ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})
50            end) =~ "Couldn't find scheduled activity: 42"
51   end
52 end