1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ScheduledActivityTest do
8 alias Pleroma.ScheduledActivity
12 DataCase.ensure_local_uploader(context)
15 describe "creation" do
16 test "when daily user limit is exceeded" do
20 NaiveDateTime.utc_now()
21 |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
22 |> NaiveDateTime.to_iso8601()
24 attrs = %{params: %{}, scheduled_at: today}
25 {:ok, _} = ScheduledActivity.create(user, attrs)
26 {:ok, _} = ScheduledActivity.create(user, attrs)
27 {:error, changeset} = ScheduledActivity.create(user, attrs)
28 assert changeset.errors == [scheduled_at: {"daily limit exceeded", []}]
31 test "when total user limit is exceeded" do
35 NaiveDateTime.utc_now()
36 |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
37 |> NaiveDateTime.to_iso8601()
40 NaiveDateTime.utc_now()
41 |> NaiveDateTime.add(:timer.hours(36), :millisecond)
42 |> NaiveDateTime.to_iso8601()
44 {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: today})
45 {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: today})
46 {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
47 {:error, changeset} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
48 assert changeset.errors == [scheduled_at: {"total limit exceeded", []}]
51 test "when scheduled_at is earlier than 5 minute from now" do
55 NaiveDateTime.utc_now()
56 |> NaiveDateTime.add(:timer.minutes(4), :millisecond)
57 |> NaiveDateTime.to_iso8601()
59 attrs = %{params: %{}, scheduled_at: scheduled_at}
60 {:error, changeset} = ScheduledActivity.create(user, attrs)
61 assert changeset.errors == [scheduled_at: {"must be at least 5 minutes from now", []}]