1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTimeTest do
6 alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime
7 use Pleroma.DataCase, async: true
9 test "it validates an xsd:Datetime" do
11 "2004-04-12T13:20:00",
12 "2004-04-12T13:20:15.5",
13 "2004-04-12T13:20:00-05:00",
14 "2004-04-12T13:20:00Z"
24 assert {:ok, "2004-04-01T12:00:00Z"} == DateTime.cast("2004-04-01T12:00:00Z")
26 Enum.each(valid_strings, fn date_time ->
27 result = DateTime.cast(date_time)
28 assert {:ok, _} = result
31 Enum.each(invalid_strings, fn date_time ->
32 result = DateTime.cast(date_time)
33 assert :error == result