Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.ScheduledActivityTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.DataCase
  7. alias Pleroma.ScheduledActivity
  8. import Pleroma.Factory
  9. setup context do
  10. DataCase.ensure_local_uploader(context)
  11. end
  12. describe "creation" do
  13. test "when daily user limit is exceeded" do
  14. user = insert(:user)
  15. today =
  16. NaiveDateTime.utc_now()
  17. |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
  18. |> NaiveDateTime.to_iso8601()
  19. attrs = %{params: %{}, scheduled_at: today}
  20. {:ok, _} = ScheduledActivity.create(user, attrs)
  21. {:ok, _} = ScheduledActivity.create(user, attrs)
  22. {:error, changeset} = ScheduledActivity.create(user, attrs)
  23. assert changeset.errors == [scheduled_at: {"daily limit exceeded", []}]
  24. end
  25. test "when total user limit is exceeded" do
  26. user = insert(:user)
  27. today =
  28. NaiveDateTime.utc_now()
  29. |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
  30. |> NaiveDateTime.to_iso8601()
  31. tomorrow =
  32. NaiveDateTime.utc_now()
  33. |> NaiveDateTime.add(:timer.hours(36), :millisecond)
  34. |> NaiveDateTime.to_iso8601()
  35. {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: today})
  36. {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: today})
  37. {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
  38. {:error, changeset} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
  39. assert changeset.errors == [scheduled_at: {"total limit exceeded", []}]
  40. end
  41. test "when scheduled_at is earlier than 5 minute from now" do
  42. user = insert(:user)
  43. scheduled_at =
  44. NaiveDateTime.utc_now()
  45. |> NaiveDateTime.add(:timer.minutes(4), :millisecond)
  46. |> NaiveDateTime.to_iso8601()
  47. attrs = %{params: %{}, scheduled_at: scheduled_at}
  48. {:error, changeset} = ScheduledActivity.create(user, attrs)
  49. assert changeset.errors == [scheduled_at: {"must be at least 5 minutes from now", []}]
  50. end
  51. end
  52. end