diff options
author | lain <lain@soykaf.club> | 2020-03-19 18:00:55 +0100 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-03-19 18:00:55 +0100 |
commit | 3c2c32b460c2d942d085725d14e77a96c4a01e4c (patch) | |
tree | 1542ba8f33738650c561a1f944ae7ce9e16dd116 /test/web/activity_pub/object_validators | |
parent | ac5c2b66b9f106bad117708cf74e3007c434d09e (diff) | |
parent | d4bafabfd14887e61eb5bc1d877035dcfebbd33f (diff) | |
download | pleroma-3c2c32b460c2d942d085725d14e77a96c4a01e4c.tar.gz pleroma-3c2c32b460c2d942d085725d14e77a96c4a01e4c.zip |
Merge branch 'remake-remodel' into develop
Diffstat (limited to 'test/web/activity_pub/object_validators')
-rw-r--r-- | test/web/activity_pub/object_validators/note_validator_test.exs | 35 | ||||
-rw-r--r-- | test/web/activity_pub/object_validators/types/date_time_test.exs | 32 |
2 files changed, 67 insertions, 0 deletions
diff --git a/test/web/activity_pub/object_validators/note_validator_test.exs b/test/web/activity_pub/object_validators/note_validator_test.exs new file mode 100644 index 000000000..2bcd75e25 --- /dev/null +++ b/test/web/activity_pub/object_validators/note_validator_test.exs @@ -0,0 +1,35 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidatorTest do + use Pleroma.DataCase + + alias Pleroma.Web.ActivityPub.ObjectValidators.NoteValidator + alias Pleroma.Web.ActivityPub.Utils + + import Pleroma.Factory + + describe "Notes" do + setup do + user = insert(:user) + + note = %{ + "id" => Utils.generate_activity_id(), + "type" => "Note", + "actor" => user.ap_id, + "to" => [user.follower_address], + "cc" => [], + "content" => "Hellow this is content.", + "context" => "xxx", + "summary" => "a post" + } + + %{user: user, note: note} + end + + test "a basic note validates", %{note: note} do + %{valid?: true} = NoteValidator.cast_and_validate(note) + end + end +end diff --git a/test/web/activity_pub/object_validators/types/date_time_test.exs b/test/web/activity_pub/object_validators/types/date_time_test.exs new file mode 100644 index 000000000..3e17a9497 --- /dev/null +++ b/test/web/activity_pub/object_validators/types/date_time_test.exs @@ -0,0 +1,32 @@ +defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.DateTimeTest do + alias Pleroma.Web.ActivityPub.ObjectValidators.Types.DateTime + use Pleroma.DataCase + + test "it validates an xsd:Datetime" do + valid_strings = [ + "2004-04-12T13:20:00", + "2004-04-12T13:20:15.5", + "2004-04-12T13:20:00-05:00", + "2004-04-12T13:20:00Z" + ] + + invalid_strings = [ + "2004-04-12T13:00", + "2004-04-1213:20:00", + "99-04-12T13:00", + "2004-04-12" + ] + + assert {:ok, "2004-04-01T12:00:00Z"} == DateTime.cast("2004-04-01T12:00:00Z") + + Enum.each(valid_strings, fn date_time -> + result = DateTime.cast(date_time) + assert {:ok, _} = result + end) + + Enum.each(invalid_strings, fn date_time -> + result = DateTime.cast(date_time) + assert :error == result + end) + end +end |