Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 67 additions & 10 deletions src/xapi_schema/spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -993,7 +1037,9 @@
:context/platform
:context/language
:context/statement
:context/extensions))))
:context/extensions
:context/contextAgents
:context/contextGroups))))

;; Attachments

Expand Down Expand Up @@ -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 []))
4 changes: 2 additions & 2 deletions src/xapi_schema/spec/regex.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions test/xapi_schema/spec/regex_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,20 @@
(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"
(is (and (re-matches xAPIVersionRegEx "1.0.0")
(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"
Expand Down
Loading