logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

date_time_test.exs (998B)


  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. defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTimeTest do
  5. alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime
  6. use Pleroma.DataCase, async: true
  7. test "it validates an xsd:Datetime" do
  8. valid_strings = [
  9. "2004-04-12T13:20:00",
  10. "2004-04-12T13:20:15.5",
  11. "2004-04-12T13:20:00-05:00",
  12. "2004-04-12T13:20:00Z"
  13. ]
  14. invalid_strings = [
  15. "2004-04-12T13:00",
  16. "2004-04-1213:20:00",
  17. "99-04-12T13:00",
  18. "2004-04-12"
  19. ]
  20. assert {:ok, "2004-04-01T12:00:00Z"} == DateTime.cast("2004-04-01T12:00:00Z")
  21. Enum.each(valid_strings, fn date_time ->
  22. result = DateTime.cast(date_time)
  23. assert {:ok, _} = result
  24. end)
  25. Enum.each(invalid_strings, fn date_time ->
  26. result = DateTime.cast(date_time)
  27. assert :error == result
  28. end)
  29. end
  30. end