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))}
: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)))

View file

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

View file

@ -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",

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