diff --git a/src/main/com/yetanalytics/lrs/pedestal/interceptor.cljc b/src/main/com/yetanalytics/lrs/pedestal/interceptor.cljc index 32daffb..7f075c7 100644 --- a/src/main/com/yetanalytics/lrs/pedestal/interceptor.cljc +++ b/src/main/com/yetanalytics/lrs/pedestal/interceptor.cljc @@ -43,8 +43,15 @@ (get-in ctx [:request :headers "x-experience-api-version"]))] (assoc ctx :com.yetanalytics.lrs/version - ;; the spec requires this shorthand - (if (= "2.0" version) "2.0.0" version)) + (cond + ;; the spec requires this shorthand + (= "2.0" version) "2.0.0" + ;; We explicitly allow versions 1.0.0-1.0.2, but treat + ;; treat them as 1.0.3 + (contains? #{"1.0.0" + "1.0.1" + "1.0.2"} version) "1.0.3" + :else version)) ;; allow without, it will be turned into an error down the line ctx))})) diff --git a/src/main/com/yetanalytics/lrs/pedestal/interceptor/xapi.cljc b/src/main/com/yetanalytics/lrs/pedestal/interceptor/xapi.cljc index bcdef81..8e9f535 100644 --- a/src/main/com/yetanalytics/lrs/pedestal/interceptor/xapi.cljc +++ b/src/main/com/yetanalytics/lrs/pedestal/interceptor/xapi.cljc @@ -18,7 +18,6 @@ {:status 400 :headers {#?(:cljs "Content-Type" :clj "content-type") "application/json" - ;; TODO: dispatch on type in ctx "x-experience-api-version" (:com.yetanalytics.lrs/version ctx diff --git a/src/test/com/yetanalytics/lrs_test.clj b/src/test/com/yetanalytics/lrs_test.clj index 90ae010..e76cb33 100644 --- a/src/test/com/yetanalytics/lrs_test.clj +++ b/src/test/com/yetanalytics/lrs_test.clj @@ -1,5 +1,5 @@ (ns com.yetanalytics.lrs-test - (:require [clojure.test :refer [deftest testing is]] + (:require [clojure.test :refer [deftest testing is are]] [com.yetanalytics.test-support :as support :refer [deftest-check-ns]] [com.yetanalytics.lrs.impl.memory :as mem] [com.yetanalytics.lrs :as lrs] @@ -9,7 +9,10 @@ [clojure.spec.alpha :as s] [xapi-schema.spec :as xs] [com.yetanalytics.lrs.xapi.statements.timestamp :as t] - [clojure.spec.test.alpha :as stest])) + [clojure.spec.test.alpha :as stest] + [io.pedestal.http :as http] + [babashka.curl :as curl] + [cheshire.core :as json])) (alias 'stc 'clojure.spec.test.check) @@ -255,3 +258,29 @@ {:statementId id} #{"en-US"}) [:statement "version"])))))))) + +(deftest accept-version-test + (let [lrs (support/test-server)] + (testing "Accepts versions 1.0.0-1.0.3" + (try + (http/start lrs) + (are [version-header + result-status] + (= result-status + (:status + (curl/post + "http://localhost:8080/xapi/statements" + {:basic-auth ["username" "password"] + :headers {"X-Experience-API-Version" version-header + "Content-Type" "application/json;"} + :body (json/generate-string test-statements) + :throw false}))) + "0.9.5" 400 + "1.0.0" 200 + "1.0.1" 200 + "1.0.2" 200 + "1.0.3" 200 + "1.0.4" 400 + "2.0.0" 200) + (finally + (http/stop lrs))))))