X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fscheduled_activity_test.exs;h=7faa5660daa5856269c42873075bfddf12229a09;hb=dda65f7799e9dfa2e7b87389848eeee10993a858;hp=c49c65c0acb31c329aa109d9d960c67c4c77feec;hpb=fc92a0fd8d5be0352f4791b79bda04960f36f707;p=akkoma
diff --git a/test/scheduled_activity_test.exs b/test/scheduled_activity_test.exs
index c49c65c0a..7faa5660d 100644
--- a/test/scheduled_activity_test.exs
+++ b/test/scheduled_activity_test.exs
@@ -1,22 +1,58 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ScheduledActivityTest do
use Pleroma.DataCase
- alias Pleroma.Config
alias Pleroma.DataCase
alias Pleroma.ScheduledActivity
- alias Pleroma.Web.ActivityPub.ActivityPub
import Pleroma.Factory
+ setup do: clear_config([ScheduledActivity, :enabled])
+
setup context do
- Config.put([ScheduledActivity, :daily_user_limit], 2)
- Config.put([ScheduledActivity, :total_user_limit], 3)
DataCase.ensure_local_uploader(context)
end
describe "creation" do
+ test "scheduled activities with jobs when ScheduledActivity enabled" do
+ Pleroma.Config.put([ScheduledActivity, :enabled], true)
+ user = insert(:user)
+
+ today =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+
+ attrs = %{params: %{}, scheduled_at: today}
+ {:ok, sa1} = ScheduledActivity.create(user, attrs)
+ {:ok, sa2} = ScheduledActivity.create(user, attrs)
+
+ jobs =
+ Repo.all(from(j in Oban.Job, where: j.queue == "scheduled_activities", select: j.args))
+
+ assert jobs == [%{"activity_id" => sa1.id}, %{"activity_id" => sa2.id}]
+ end
+
+ test "scheduled activities without jobs when ScheduledActivity disabled" do
+ Pleroma.Config.put([ScheduledActivity, :enabled], false)
+ user = insert(:user)
+
+ today =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+
+ attrs = %{params: %{}, scheduled_at: today}
+ {:ok, _sa1} = ScheduledActivity.create(user, attrs)
+ {:ok, _sa2} = ScheduledActivity.create(user, attrs)
+
+ jobs =
+ Repo.all(from(j in Oban.Job, where: j.queue == "scheduled_activities", select: j.args))
+
+ assert jobs == []
+ end
+
test "when daily user limit is exceeded" do
user = insert(:user)
@@ -28,6 +64,7 @@ defmodule Pleroma.ScheduledActivityTest do
attrs = %{params: %{}, scheduled_at: today}
{:ok, _} = ScheduledActivity.create(user, attrs)
{:ok, _} = ScheduledActivity.create(user, attrs)
+
{:error, changeset} = ScheduledActivity.create(user, attrs)
assert changeset.errors == [scheduled_at: {"daily limit exceeded", []}]
end
@@ -42,7 +79,7 @@ defmodule Pleroma.ScheduledActivityTest do
tomorrow =
NaiveDateTime.utc_now()
- |> NaiveDateTime.add(:timer.hours(24), :millisecond)
+ |> NaiveDateTime.add(:timer.hours(36), :millisecond)
|> NaiveDateTime.to_iso8601()
{:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: today})
@@ -64,30 +101,5 @@ defmodule Pleroma.ScheduledActivityTest do
{:error, changeset} = ScheduledActivity.create(user, attrs)
assert changeset.errors == [scheduled_at: {"must be at least 5 minutes from now", []}]
end
-
- test "excludes attachments belonging to another user" do
- user = insert(:user)
- another_user = insert(:user)
-
- scheduled_at =
- NaiveDateTime.utc_now()
- |> NaiveDateTime.add(:timer.minutes(10), :millisecond)
- |> NaiveDateTime.to_iso8601()
-
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- {:ok, user_upload} = ActivityPub.upload(file, actor: user.ap_id)
- {:ok, another_user_upload} = ActivityPub.upload(file, actor: another_user.ap_id)
-
- media_ids = [user_upload.id, another_user_upload.id]
- attrs = %{params: %{"media_ids" => media_ids}, scheduled_at: scheduled_at}
- {:ok, scheduled_activity} = ScheduledActivity.create(user, attrs)
- assert to_string(user_upload.id) in scheduled_activity.params["media_ids"]
- refute to_string(another_user_upload.id) in scheduled_activity.params["media_ids"]
- end
end
end