From e998fe28907bb5df5d437ad4c9b949758ffc3c28 Mon Sep 17 00:00:00 2001 From: Clemens Date: Wed, 2 Aug 2023 11:32:47 +0200 Subject: [PATCH] Added spec assert --- .../activity_pub_poc/core.cljc | 16 +++++++++------- .../activity_pub_poc/activitystreams2_test.cljc | 1 + .../activity_pub_poc/core_test.cljc | 1 + .../activity_pub_poc/xsd_test.cljc | 6 ++++++ 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd_test.cljc diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc index d725f0c..1119898 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc @@ -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)) \ No newline at end of file +(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))) \ No newline at end of file diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.cljc b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.cljc index aca1290..bd1096d 100644 --- a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.cljc +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2_test.cljc @@ -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"))) diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc index 78498a9..eb06645 100644 --- a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc @@ -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", diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd_test.cljc b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd_test.cljc new file mode 100644 index 0000000..56bfcca --- /dev/null +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/xsd_test.cljc @@ -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])) \ No newline at end of file