alias Pleroma.ScheduledActivity
import Pleroma.Factory
+ import Ecto.Query
+
+ clear_config([ScheduledActivity, :enabled])
- test "shows scheduled activities", %{conn: conn} do
- user = insert(:user)
+ test "shows scheduled activities" do
+ %{user: user, conn: conn} = oauth_access(["read:statuses"])
+
scheduled_activity_id1 = insert(:scheduled_activity, user: user).id |> to_string()
scheduled_activity_id2 = insert(:scheduled_activity, user: user).id |> to_string()
scheduled_activity_id3 = insert(:scheduled_activity, user: user).id |> to_string()
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
end
- test "updates a scheduled activity", %{conn: conn} do
+ test "updates a scheduled activity" do
+ Pleroma.Config.put([ScheduledActivity, :enabled], true)
- user = insert(:user)
+ %{user: user, conn: conn} = oauth_access(["write:statuses"])
- scheduled_activity = insert(:scheduled_activity, user: user)
- scheduled_at =
- NaiveDateTime.add(
- NaiveDateTime.utc_now(),
- :timer.minutes(60),
- :millisecond
- )
- new_scheduled_at =
- NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
++ scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
+
+ {:ok, scheduled_activity} =
+ ScheduledActivity.create(
+ user,
+ %{
+ scheduled_at: scheduled_at,
+ params: build(:note).data
+ }
+ )
+
- scheduled_activity_job =
- Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
++ job = Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
+
- assert scheduled_activity_job.args == %{"activity_id" => scheduled_activity.id}
++ assert job.args == %{"activity_id" => scheduled_activity.id}
++ assert DateTime.truncate(job.scheduled_at, :second) == to_datetime(scheduled_at)
+
- assert DateTime.truncate(scheduled_activity_job.scheduled_at, :second) ==
- to_datetime(scheduled_at)
-
- new_scheduled_at =
- NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
++ new_scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 120)
res_conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
+ put(conn, "/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
scheduled_at: new_scheduled_at
})
assert %{"scheduled_at" => expected_scheduled_at} = json_response(res_conn, 200)
assert expected_scheduled_at == Pleroma.Web.CommonAPI.Utils.to_masto_date(new_scheduled_at)
- scheduled_activity_job = refresh_record(scheduled_activity_job)
++ job = refresh_record(job)
+
- assert DateTime.truncate(scheduled_activity_job.scheduled_at, :second) ==
- to_datetime(new_scheduled_at)
++ assert DateTime.truncate(job.scheduled_at, :second) == to_datetime(new_scheduled_at)
- res_conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
+ res_conn = put(conn, "/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
end
- test "deletes a scheduled activity", %{conn: conn} do
+ test "deletes a scheduled activity" do
+ Pleroma.Config.put([ScheduledActivity, :enabled], true)
- user = insert(:user)
+ %{user: user, conn: conn} = oauth_access(["write:statuses"])
- scheduled_activity = insert(:scheduled_activity, user: user)
++ scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
+
+ {:ok, scheduled_activity} =
+ ScheduledActivity.create(
+ user,
+ %{
- scheduled_at:
- NaiveDateTime.add(
- NaiveDateTime.utc_now(),
- :timer.minutes(60),
- :millisecond
- ),
++ scheduled_at: scheduled_at,
+ params: build(:note).data
+ }
+ )
+
- scheduled_activity_job =
- Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
++ job = Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities"))
+
- assert scheduled_activity_job.args == %{"activity_id" => scheduled_activity.id}
++ assert job.args == %{"activity_id" => scheduled_activity.id}
res_conn =
conn
|> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
assert %{} = json_response(res_conn, 200)
- assert nil == Repo.get(ScheduledActivity, scheduled_activity.id)
+ refute Repo.get(ScheduledActivity, scheduled_activity.id)
- refute Repo.get(Oban.Job, scheduled_activity_job.id)
++ refute Repo.get(Oban.Job, job.id)
res_conn =
conn