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
11 changes: 9 additions & 2 deletions src/main/com/yetanalytics/lrs/pedestal/interceptor.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 31 additions & 2 deletions src/test/com/yetanalytics/lrs_test.clj
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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)

Expand Down Expand Up @@ -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))))))
Loading