Skip to content
Merged
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
15 changes: 11 additions & 4 deletions src/com/yetanalytics/lrs_reactions/spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
val]}]
(if (= op "like")
(if-let [{ref-path :path} ref]
(let [{:keys [leaf-type]} (path/analyze-path ref-path)]
(let [{:keys [leaf-type]} (path/analyze-path
ref-path
:xapi-version xs/*xapi-version*)]
(= 'string leaf-type))
(= :string
(first val)))
Expand All @@ -54,7 +56,9 @@
(if path
(let [{:keys [valid?
leaf-type
next-keys]} (path/analyze-path path)]
next-keys]} (path/analyze-path
path
:xapi-version xs/*xapi-version*)]
(and valid?
(if (= "contains" op)
(or (= '[idx] next-keys) (= 'json leaf-type))
Expand All @@ -63,7 +67,9 @@
(= 'json leaf-type) ;; anything goes
(if-let [{ref-path :path} ref]
(let [{ref-leaf-type :leaf-type}
(path/analyze-path ref-path)]
(path/analyze-path
ref-path
:xapi-version xs/*xapi-version*)]
(= leaf-type ref-leaf-type))
(= (name leaf-type)
(name (first val)))))))))
Expand Down Expand Up @@ -95,7 +101,8 @@

(defn valid-identity-path?
[path]
(some? (:leaf-type (path/analyze-path path))))
(some? (:leaf-type (path/analyze-path path
:xapi-version xs/*xapi-version*))))

(s/def ::identityPaths
(s/every (s/and ::path
Expand Down
44 changes: 42 additions & 2 deletions test/com/yetanalytics/lrs_reactions/spec_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns com.yetanalytics.lrs-reactions.spec-test
(:require [clojure.test :refer [deftest are testing]]
[clojure.spec.alpha :as s]
[com.yetanalytics.lrs-reactions.spec :as rs]))
[com.yetanalytics.lrs-reactions.spec :as rs]
[xapi-schema.spec :as xs]))

(deftest valid-like-val-test
(testing "validates value in case of like op"
Expand All @@ -20,6 +20,24 @@
:ref {:condition "whatever"
:path ["result" "score" "scaled"]}} false)))

(deftest valid-like-val-2-test
(testing "validates value in case of like op (xAPI 2.0.0)"
(are [clause result]
(binding [xs/*xapi-version* "2.0.0"]
(= result (true? (rs/valid-like-val? clause))))
{:path ["context" "contextAgents" 0 "relevantTypes" 0]
:op "like"
:val [:string "https://example.org/friend"]} true
;; invalid val type
{:path ["context" "contextAgents" 0 "relevantTypes" 0]
:op "like"
:val [:number 1]} false
;; invalid ref path type
{:path ["context" "contextAgents" 0 "relevantTypes" 0]
:op "like"
:ref {:condition "whatever"
:path ["result" "score" "scaled"]}} false)))

(deftest valid-clause-path-test
(testing "validates logic clause paths"
(are [clause result]
Expand Down Expand Up @@ -48,6 +66,19 @@
:ref {:condition "whatever"
:path ["id"]}} false)))

(deftest valid-clause-path-2-test
(testing "validates logic clause paths (xAPI 2.0.0)"
(are [clause result]
(binding [xs/*xapi-version* "2.0.0"]
(= result (true? (rs/valid-clause-path? clause))))
{:path ["context" "contextAgents" 0 "agent" "name"],
:op "eq",
:val [:string "Bob"]} true
;; incomplete path
{:path ["context" "contextAgents" 0 "agent"],
:op "eq",
:val [:string "bob"]} false)))

(deftest valid-identity-path-test
(testing "validates identity paths"
(are [path result]
Expand All @@ -57,3 +88,12 @@
["object"] false
;; not xapi
["foo"] false)))

(deftest valid-identity-path-2-test
(testing "validates identity paths"
(are [path result]
(binding [xs/*xapi-version* "2.0.0"]
(= result (rs/valid-identity-path? path)))
["context" "contextAgents" 0 "agent" "mbox"] true
;; incomplete
["context" "contextAgents" 0 "agent"] false)))
Loading