add functional-property
This commit is contained in:
parent
3eff9a628e
commit
a612f070db
2 changed files with 26 additions and 16 deletions
|
@ -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))
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
(deftest should-serailize
|
||||
(is (= (str "{\"@context\":\"https://www.w3.org/ns/activitystreams\","
|
||||
"\"id\":\"http://example.org/likes/1\","
|
||||
"\"summary\":\"Sally liked a note\","
|
||||
"\"type\":\"Like\","
|
||||
"\"actor\":{"
|
||||
|
@ -14,8 +15,9 @@
|
|||
"\"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"}))))
|
Loading…
Reference in a new issue