add functional-property

This commit is contained in:
Michael Jerger 2023-08-02 09:58:36 +02:00
parent 3eff9a628e
commit a612f070db
2 changed files with 26 additions and 16 deletions

View file

@ -5,10 +5,18 @@
[org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as as]
[clojure.data.json :as json]))
( defn serialize-element [elem]
(if (and (sh/is-functional-property? (key elem))
(sequential? (val elem)))
{(key elem) (first (val elem))}
{(key elem) (val elem)}))
(defn serialize
[as-map]
(json/write-str
(assoc
as-map
(keyword "@context")
"https://www.w3.org/ns/activitystreams")))
(map
serialize-element
(merge
{(keyword "@context") "https://www.w3.org/ns/activitystreams"}
as-map))
:escape-slash false))

View file

@ -6,16 +6,18 @@
[org.domaindrivenarchitecture.activity-pub-poc.core :as sut]))
(deftest should-serailize
(is (= (str "{\"@context\": \"https://www.w3.org/ns/activitystreams\", "
"\"summary\": \"Sally liked a note\", "
"\"type\": \"Like\", "
"\"actor\": {"
"\"type\": \"Person\", "
"\"name\": \"Sally\"}, "
"\"object\": \"http://example.org/notes/1\"}")
(is (= (str "{\"@context\":\"https://www.w3.org/ns/activitystreams\","
"\"id\":\"http://example.org/likes/1\","
"\"summary\":\"Sally liked a note\","
"\"type\":\"Like\","
"\"actor\":{"
"\"type\":\"Person\","
"\"name\":\"Sally\"},"
"\"object\":\"http://example.org/notes/1\"}")
(sut/serialize
{:summary "Sally liked a note",
:type "Like",
:actor {:type "Person",
:name "Sally"},
:object "http://example.org/notes/1"}))))
{::as/id ["http://example.org/likes/1"]
::as/summary "Sally liked a note",
::as/type "Like",
::as/actor {::as/type "Person",
::as/name "Sally"},
::as/object "http://example.org/notes/1"}))))