diff --git a/src/xapi_schema/spec.cljc b/src/xapi_schema/spec.cljc index 05c351f..9757d79 100644 --- a/src/xapi_schema/spec.cljc +++ b/src/xapi_schema/spec.cljc @@ -281,10 +281,7 @@ (s/with-gen (s/and string? (partial re-matches xAPIVersionRegEx)) - #(sgen/fmap (fn [i] - (#?(:clj format - :cljs gstring/format) "1.0.%d" i)) - (sgen/int)))) + #(sgen/return "2.0.0"))) (s/def ::sha2 (s/with-gen @@ -815,17 +812,17 @@ (-> scores (assoc :score/min raw) (assoc :score/raw min)) - + (and min max (< max min)) (-> scores (assoc :score/min max) (assoc :score/max min)) - + (and raw max (< max raw)) (-> scores (assoc :score/raw max) (assoc :score/max raw)) - + :else scores)) @@ -973,6 +970,51 @@ (s/def :context/extensions ::extensions) +;; 2.0.x compat + +;; contextAgents +(s/def :contextAgent/objectType #{"contextAgent"}) +(s/def :contextAgent/agent ::agent) +(s/def :contextAgent/relevantTypes + (s/every ::iri + :into [] + :min-count 1)) + +(s/def ::context-agent + (conform-ns "contextAgent" + (s/and + (s/keys :req [:contextAgent/objectType + :contextAgent/agent] + :opt [:contextAgent/relevantTypes]) + (restrict-keys :contextAgent/objectType + :contextAgent/agent + :contextAgent/relevantTypes)))) +(s/def :context/contextAgents + (s/every ::context-agent + :into [])) + +;; contextGroups + +(s/def :contextGroup/objectType #{"contextGroup"}) +(s/def :contextGroup/group ::group) +(s/def :contextGroup/relevantTypes + (s/every ::iri + :into [] + :min-count 1)) + +(s/def ::context-group + (conform-ns "contextGroup" + (s/and + (s/keys :req [:contextGroup/objectType + :contextGroup/group] + :opt [:contextGroup/relevantTypes]) + (restrict-keys :contextGroup/objectType + :contextGroup/group + :contextGroup/relevantTypes)))) +(s/def :context/contextGroups + (s/every ::context-group + :into [])) + (s/def ::context (conform-ns "context" (s/and @@ -984,7 +1026,9 @@ :context/platform :context/language :context/statement - :context/extensions]) + :context/extensions + :context/contextAgents + :context/contextGroups]) (restrict-keys :context/registration :context/instructor :context/team @@ -993,7 +1037,9 @@ :context/platform :context/language :context/statement - :context/extensions)))) + :context/extensions + :context/contextAgents + :context/contextGroups)))) ;; Attachments @@ -1326,8 +1372,19 @@ (some-> s :statement/object :statement-ref/objectType) true))))) +(defn unique-statement-ids? + "Spec predicate to ensure that the IDs of a list of statements are unique." + [statements] + (let [ids (keep #(get % "id") statements)] + (or + (empty? ids) + (reduce distinct? ids) + ::s/invalid))) + (s/def ::statements - (s/coll-of ::statement :into [])) + (s/and + (s/coll-of ::statement :into []) + unique-statement-ids?)) (s/def ::lrs-statements (s/coll-of ::lrs-statement :into [])) diff --git a/src/xapi_schema/spec/regex.cljc b/src/xapi_schema/spec/regex.cljc index f0165d9..fc57e1a 100644 --- a/src/xapi_schema/spec/regex.cljc +++ b/src/xapi_schema/spec/regex.cljc @@ -117,7 +117,7 @@ ;; Time time (str "(?:" hour ":" min ":" sec sec-frac "?" ")") date (str "(?:" year "-" month "-" day ")")] - (str date "T" time))) + (str date "[T\\s]" time))) (def TimestampRegEx ; RFC 3339 (let [;; Time @@ -148,7 +148,7 @@ (def xAPIVersionRegEx (let [suf-part "[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*" suffix (str "(\\.[0-9]+(?:-" suf-part ")?(?:\\+" suf-part ")?)?") - ver-str (str "^1\\.0" suffix "$")] + ver-str (str "^(1\\.0" suffix ")|(2\\.0\\.0)$")] (re-pattern ver-str))) (def Base64RegEx diff --git a/test/xapi_schema/spec/regex_test.cljc b/test/xapi_schema/spec/regex_test.cljc index 048d57a..c2356e4 100644 --- a/test/xapi_schema/spec/regex_test.cljc +++ b/test/xapi_schema/spec/regex_test.cljc @@ -145,7 +145,9 @@ (is (not (re-matches TimestampRegEx "20150513T15Z"))) (is (not (re-matches TimestampRegEx "20150513T15:16:00Z"))) ;; negative offset - (is (not (re-matches TimestampRegEx "2008-09-15T15:53:00.601-00:00"))))) + (is (not (re-matches TimestampRegEx "2008-09-15T15:53:00.601-00:00")))) + (testing "matches valid but terrible stamps in rfc3339 OUTSIDE of 8601" + (is (re-matches TimestampRegEx "2015-05-13 15:16:00Z")))) (deftest xapi-version-regex-test (testing "matches xAPI 1.0.X versions" @@ -153,7 +155,10 @@ (re-matches xAPIVersionRegEx "1.0.2") (re-matches xAPIVersionRegEx "1.0") (re-matches xAPIVersionRegEx "1.0.32-abc.def+ghi.jkl"))) - (is (not (re-matches xAPIVersionRegEx "0.9.5"))))) + (is (not (re-matches xAPIVersionRegEx "0.9.5")))) + (testing "matches xAPI 2.0.0 version only" + (is (and (re-matches xAPIVersionRegEx "2.0.0") + (not (re-matches xAPIVersionRegEx "2.0.2")))))) (deftest duration-regex-test (testing "matches ISO durations"