Added spec assert

This commit is contained in:
Clemens 2023-08-02 11:32:47 +02:00
parent 11c87848ca
commit e998fe2890
4 changed files with 17 additions and 7 deletions

View file

@ -24,10 +24,12 @@
{k (first (normalize-value v))} {k (first (normalize-value v))}
:else {k (normalize-value v)}))) :else {k (normalize-value v)})))
(defn serialize (defn-spec serialize string?
[as-map] [spec s/spec?
(json/write-str as-map map?]
(merge (let [speced-map (assert (s/valid? spec as-map))]
{(keyword "@context") "https://www.w3.org/ns/activitystreams"} (json/write-str
(walk/walk normalize-functional-property identity as-map)) (merge
:escape-slash false)) {(keyword "@context") "https://www.w3.org/ns/activitystreams"}
(walk/walk normalize-functional-property identity speced-map))
:escape-slash false)))

View file

@ -6,6 +6,7 @@
(deftest id-test (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 (s/valid? ::sut/id ["https://social.bla/alyssa/status/RANDOMHASH"]))
(is (not (s/valid? ::sut/id nil))) (is (not (s/valid? ::sut/id nil)))
(is (not (s/valid? ::sut/id 2))) (is (not (s/valid? ::sut/id 2)))
(is (not (s/valid? ::sut/id "https://no-uri:abc"))) (is (not (s/valid? ::sut/id "https://no-uri:abc")))

View file

@ -17,6 +17,7 @@
"\"name\":\"Sally\"}," "\"name\":\"Sally\"},"
"\"object\":\"http://example.org/notes/1\"}") "\"object\":\"http://example.org/notes/1\"}")
(sut/serialize (sut/serialize
::as/Like
{::as/id ["http://example.org/likes/1"] {::as/id ["http://example.org/likes/1"]
::as/summary "Sally liked a note", ::as/summary "Sally liked a note",
::as/type "Like", ::as/type "Like",

View file

@ -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]))