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
22 changes: 15 additions & 7 deletions src/main/com/yetanalytics/lrs/impl/memory.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,20 @@

#_{:clj-kondo/ignore [:unused-private-var]}
(defn- store-statements-sync
[state statements attachments]
(try (let [prepared-statements
[ctx state statements attachments]
(try (let [{version :com.yetanalytics.lrs/version
:or {version "1.0.3"}}
ctx
prepared-statements
(map
(fn [s stamp]
(ss/prepare-statement
(assoc s "stored" stamp)))
(assoc s
"stored" stamp
"version" (or (get s "version")
(case version
"1.0.3" "1.0.0"
"2.0.0" "2.0.0")))))
statements
(timestamp/stamp-seq))]
(swap! state
Expand Down Expand Up @@ -885,8 +893,8 @@
(-get-about [_ _ _]
(get-about state))
`~p/StatementsResource
(-store-statements [_ _ _ statements attachments]
(store-statements-sync state statements attachments))
(-store-statements [_ ctx _ statements attachments]
(store-statements-sync ctx state statements attachments))
(-get-statements [_ _ _ params ltags]
(get-statements-sync state xapi-path-prefix params ltags))
(-consistent-through [_ _ _]
Expand Down Expand Up @@ -920,8 +928,8 @@
(-get-about-async [lrs _ auth-identity]
(a/go (get-about state)))
`~p/StatementsResourceAsync
(-store-statements-async [lrs _ auth-identity stmts attachments]
(a/go (store-statements-sync state stmts attachments)))
(-store-statements-async [lrs ctx auth-identity stmts attachments]
(a/go (store-statements-sync ctx state stmts attachments)))
(-get-statements-async [_ _ _ params ltags]
(get-statements-async state xapi-path-prefix params ltags))
(-consistent-through-async [_ _ _]
Expand Down
2 changes: 1 addition & 1 deletion src/main/com/yetanalytics/lrs/xapi/statements.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"stored" stored
"timestamp" timestamp
"authority" authority
"version" (or version "2.0.0")))))
"version" (or version "1.0.0")))))

(s/fdef prepare-statement
:args (s/cat :statement ::xs/statement)
Expand Down
31 changes: 21 additions & 10 deletions src/test/com/yetanalytics/lrs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@
;; max precision of 1 ms. That's timestamps though, looks like we have
;; no normalization going on
s-count 100
ctx-103 {:com.yetanalytics.lrs/version "1.0.3"}
lrs (doto (mem/new-lrs {:statements-result-max s-count})
(lrs/store-statements {} auth-id
(lrs/store-statements ctx-103 auth-id
(into [] (take s-count)
test-statements)
[]))
get-ss #(into []
(get-in (lrs/get-statements lrs {} auth-id % #{"en-US"})
(get-in (lrs/get-statements lrs ctx-103 auth-id % #{"en-US"})
[:statement-result :statements]))
ret-statements (get-ss {:limit 100})]
(testing (format "%s valid return statements?" (count ret-statements))
Expand Down Expand Up @@ -180,7 +181,7 @@
(is
(:statement
(lrs/get-statements lrs
{}
ctx-103
auth-id
{:statementId (cs/upper-case id)}
#{"en-US"})))))
Expand All @@ -193,7 +194,7 @@
(is
(not-empty
(get-in (lrs/get-statements lrs
{}
ctx-103
auth-id
{:registration (cs/upper-case reg)}
#{"en-US"})
Expand All @@ -204,23 +205,23 @@
id (get s "id")
lrs (doto (mem/new-lrs {:statements-result-max s-count})
(lrs/store-statements
{}
ctx-103
auth-id
[(-> s
(update "id" cs/upper-case)
(update-in ["context" "registration"] cs/upper-case))]
[]))]
(is (:statement (lrs/get-statements
lrs
{}
ctx-103
auth-id
{:statementId id}
#{"en-US"})))
;; This test will pass even w/o normalized IDs, but it makes sure we
;; don't screw up the rel index
(is (not-empty (get-in (lrs/get-statements
lrs
{}
ctx-103
auth-id
{:verb (get-in s ["verb" "id"])}
#{"en-US"})
Expand All @@ -229,7 +230,7 @@
(testing "reg index"
(is (not-empty (get-in (lrs/get-statements
lrs
{}
ctx-103
auth-id
{:registration (get-in s ["context"
"registration"])}
Expand All @@ -239,8 +240,18 @@
(testing "original case is preserved"
(is (= (cs/upper-case id)
(get-in (lrs/get-statements lrs
{}
ctx-103
auth-id
{:statementId id}
#{"en-US"})
[:statement "id"]))))))))
[:statement "id"]))))
;; impl test
(testing "version is 1.0.0"
(is (= "1.0.0"
(get-in (lrs/get-statements
lrs
ctx-103
auth-id
{:statementId id}
#{"en-US"})
[:statement "version"]))))))))
Loading