Added spec assert
This commit is contained in:
parent
11c87848ca
commit
e998fe2890
4 changed files with 17 additions and 7 deletions
|
@ -24,10 +24,12 @@
|
|||
{k (first (normalize-value v))}
|
||||
:else {k (normalize-value v)})))
|
||||
|
||||
(defn serialize
|
||||
[as-map]
|
||||
(json/write-str
|
||||
(merge
|
||||
{(keyword "@context") "https://www.w3.org/ns/activitystreams"}
|
||||
(walk/walk normalize-functional-property identity as-map))
|
||||
:escape-slash false))
|
||||
(defn-spec serialize string?
|
||||
[spec s/spec?
|
||||
as-map map?]
|
||||
(let [speced-map (assert (s/valid? spec as-map))]
|
||||
(json/write-str
|
||||
(merge
|
||||
{(keyword "@context") "https://www.w3.org/ns/activitystreams"}
|
||||
(walk/walk normalize-functional-property identity speced-map))
|
||||
:escape-slash false)))
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
(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")))
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"\"name\":\"Sally\"},"
|
||||
"\"object\":\"http://example.org/notes/1\"}")
|
||||
(sut/serialize
|
||||
::as/Like
|
||||
{::as/id ["http://example.org/likes/1"]
|
||||
::as/summary "Sally liked a note",
|
||||
::as/type "Like",
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
(ns org.domaindrivenarchitecture.activity-pub-poc.xsd-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.xsd :as sut]))
|
Loading…
Reference in a new issue