You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
4.2 KiB
Clojure

(ns org.domaindrivenarchitecture.fed-poc.activitystreams2-test
(:require
[clojure.test :refer [deftest is are testing run-tests]]
[clojure.spec.alpha :as s]
[org.domaindrivenarchitecture.fed-poc.activitystreams2 :as sut]))
(deftest id-test
(is (s/valid? ::sut/id "https://social.bla/alyssa/status/RANDOMHASH"))
(is (s/valid? ::sut/id ["https://social.bla/alyssa/status/RANDOMHASH"]))
(is (not (s/valid? ::sut/id nil)))
(is (not (s/valid? ::sut/id 2)))
(is (not (s/valid? ::sut/id "https://no-uri:abc")))
(is (not (s/valid? ::sut/id ["https://social.bla/alyssa/status/RANDOMHASH", "https://social.bla/alyssa/status/RANDOMHASH2"]))))
(deftest type-test
(is (s/valid? ::sut/type "https://social.bla/alyssa/status/RANDOMHASH"))
(is (s/valid? ::sut/type "Activity"))
(is (s/valid? ::sut/type [ "Activity"]))
(is (s/valid? ::sut/type ["https://social.bla/alyssa/status/RANDOMHASH", "https://social.bla/alyssa/status/RANDOMHASH2"]))
(is (not (s/valid? ::sut/type nil)))
(is (not (s/valid? ::sut/type [])))
(is (not (s/valid? ::sut/type 2)))
(is (not (s/valid? ::sut/type "https://no-uri:abc")))
)
(deftest object-test
(is (s/valid? ::sut/object "http://example.org/posts/1"))
(is (s/valid? ::sut/object {::sut/type "Note",
::sut/content "A simple note"}))
(is (s/valid? ::sut/object ["http://example.org/posts/1",
{::sut/type "Note",
::sut/summary "A simple note",
::sut/content "That is a tree."}])))
(deftest result-test
(is (s/valid? ::sut/result "https://social.bla/alyssa/result/RANDOMHASH"))
(is (s/valid? ::sut/result {::sut/type "http://www.types.example/flightstatus", ::sut/name "On Time"}))
(is (s/valid? ::sut/result {::sut/type "Link" ::sut/href "http://www.target.de"}))
(is (not (s/valid? ::sut/result nil)))
(is (not (s/valid? ::sut/result 47))))
(deftest attachment-test
(is (s/valid? ::sut/attachment
[{::sut/type "Image",
::sut/content "This is what he looks like.",
::sut/url "http://example.org/cat.jpeg"}])))
(deftest actor-test
(is (s/valid? ::sut/actor "http://sally.example.org"))
(is (s/valid? ::sut/actor {::sut/type "Person",
::sut/id "http://sally.example.org",
::sut/summary "Sally"}))
(is (s/valid? ::sut/actor ["http://joe.example.org",
{::sut/type "Person",
::sut/id "http://sally.example.org",
::sut/name "Sally"}])))
(deftest bcc-test
(is (s/valid? ::sut/bcc ["http://joe.example.org"])))
(deftest bto-test
(is (s/valid? ::sut/bto ["http://joe.example.org"])))
(deftest cc-test
(is (s/valid? ::sut/cc ["http://joe.example.org"])))
(deftest to-test
(is (s/valid? ::sut/to ["http://joe.example.org"])))
(deftest Activity-test
(is (s/valid? ::sut/Activity
{::sut/type "Activity",
::sut/summary "Sally did something to a note",
::sut/actor {::sut/type "Person",
::sut/name "Sally"},
::sut/object {::sut/type "Note",
::sut/name "A Note"}})))
(deftest Like-test
(is (s/valid? ::sut/Like
{::sut/summary "Sally liked a note",
::sut/type "Like",
::sut/actor {::sut/type "Person",
::sut/name "Sally"},
::sut/object "http://example.org/notes/1"}))
(is (s/valid? ::sut/Like
{::sut/id "foo",
::sut/type "Like",
::sut/actor "https://social.bla/alyssa",
::sut/object "http://example.org/notes/1"})))
(deftest Object-test
(is (s/valid? ::sut/Object
{::sut/summary "Sally liked a note",
::sut/type "Like",
::sut/actor {::sut/type "Person",
::sut/name "Sally"},
::sut/object "http://example.org/notes/1"}))
(is (s/valid? ::sut/Object
{::sut/type "Object",
::sut/id "http://www.test.example/object/1",
::sut/name "A Simple, non-specific object"})))