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.

64 lines
2.6 KiB
Clojure

(ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2-test
(:require
[clojure.test :refer [deftest is are testing run-tests]]
[clojure.spec.test.alpha :as st]
[clojure.spec.alpha :as s]
[org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as sut]))
(deftest id-test
(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 "no-uri")))
(is (not (s/valid? ::sut/id ["https://social.bla/alyssa/status/RANDOMHASH", "https://social.bla/alyssa/status/RANDOMHASH2"]))))
(deftest object-test
(is (s/valid? ::sut/object "http://example.org/posts/1"))
(is (s/valid? ::sut/object {:type "Note",
:content "A simple note"}))
(is (s/valid? ::sut/object ["http://example.org/posts/1",
{:type "Note",
:summary "A simple note",
:content "That is a tree."}])))
(deftest result-test
(is (s/valid? ::sut/result "https://social.bla/alyssa/result/RANDOMHASH"))
(is (s/valid? ::sut/result {:type "http://www.types.example/flightstatus", :name "On Time"}))
(is (s/valid? ::sut/result {:type "Link" :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
[{:type "Image",
:content "This is what he looks like.",
:url "http://example.org/cat.jpeg"}])))
(deftest actor-test
(is (s/valid? ::sut/actor "http://sally.example.org"))
(is (s/valid? ::sut/actor {:type "Person",
:id "http://sally.example.org",
:summary "Sally"}))
(is (s/valid? ::sut/actor ["http://joe.example.org",
{:type "Person",
:id "http://sally.example.org",
:name "Sally"}])))
(deftest Activity-test
(is (s/valid? ::sut/Activity
{:type "Activity",
:summary "Sally did something to a note",
:actor {:type "Person",
:name "Sally"},
:object {:type "Note",
:name "A Note"}})))
(deftest Like-test
(is (s/valid? ::sut/Like
{:summary "Sally liked a note",
:type "Like",
:actor {:type "Person",
:name "Sally"},
:object "http://example.org/notes/1"})))