Skip to content

Commit 46c7921

Browse files
authored
Mem lrs version fix (#102)
* add test to surface incorrect version issue * more explicit test supplies correct version * default to 1.0.0 in prepare-statement * version-aware store-statements fn * respect incoming statement version * default to 1.0.3 for impl
1 parent e82ab84 commit 46c7921

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

src/main/com/yetanalytics/lrs/impl/memory.cljc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,20 @@
442442

443443
#_{:clj-kondo/ignore [:unused-private-var]}
444444
(defn- store-statements-sync
445-
[state statements attachments]
446-
(try (let [prepared-statements
445+
[ctx state statements attachments]
446+
(try (let [{version :com.yetanalytics.lrs/version
447+
:or {version "1.0.3"}}
448+
ctx
449+
prepared-statements
447450
(map
448451
(fn [s stamp]
449452
(ss/prepare-statement
450-
(assoc s "stored" stamp)))
453+
(assoc s
454+
"stored" stamp
455+
"version" (or (get s "version")
456+
(case version
457+
"1.0.3" "1.0.0"
458+
"2.0.0" "2.0.0")))))
451459
statements
452460
(timestamp/stamp-seq))]
453461
(swap! state
@@ -885,8 +893,8 @@
885893
(-get-about [_ _ _]
886894
(get-about state))
887895
`~p/StatementsResource
888-
(-store-statements [_ _ _ statements attachments]
889-
(store-statements-sync state statements attachments))
896+
(-store-statements [_ ctx _ statements attachments]
897+
(store-statements-sync ctx state statements attachments))
890898
(-get-statements [_ _ _ params ltags]
891899
(get-statements-sync state xapi-path-prefix params ltags))
892900
(-consistent-through [_ _ _]
@@ -920,8 +928,8 @@
920928
(-get-about-async [lrs _ auth-identity]
921929
(a/go (get-about state)))
922930
`~p/StatementsResourceAsync
923-
(-store-statements-async [lrs _ auth-identity stmts attachments]
924-
(a/go (store-statements-sync state stmts attachments)))
931+
(-store-statements-async [lrs ctx auth-identity stmts attachments]
932+
(a/go (store-statements-sync ctx state stmts attachments)))
925933
(-get-statements-async [_ _ _ params ltags]
926934
(get-statements-async state xapi-path-prefix params ltags))
927935
(-consistent-through-async [_ _ _]

src/main/com/yetanalytics/lrs/xapi/statements.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"stored" stored
168168
"timestamp" timestamp
169169
"authority" authority
170-
"version" (or version "2.0.0")))))
170+
"version" (or version "1.0.0")))))
171171

172172
(s/fdef prepare-statement
173173
:args (s/cat :statement ::xs/statement)

src/test/com/yetanalytics/lrs_test.clj

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@
7979
;; max precision of 1 ms. That's timestamps though, looks like we have
8080
;; no normalization going on
8181
s-count 100
82+
ctx-103 {:com.yetanalytics.lrs/version "1.0.3"}
8283
lrs (doto (mem/new-lrs {:statements-result-max s-count})
83-
(lrs/store-statements {} auth-id
84+
(lrs/store-statements ctx-103 auth-id
8485
(into [] (take s-count)
8586
test-statements)
8687
[]))
8788
get-ss #(into []
88-
(get-in (lrs/get-statements lrs {} auth-id % #{"en-US"})
89+
(get-in (lrs/get-statements lrs ctx-103 auth-id % #{"en-US"})
8990
[:statement-result :statements]))
9091
ret-statements (get-ss {:limit 100})]
9192
(testing (format "%s valid return statements?" (count ret-statements))
@@ -180,7 +181,7 @@
180181
(is
181182
(:statement
182183
(lrs/get-statements lrs
183-
{}
184+
ctx-103
184185
auth-id
185186
{:statementId (cs/upper-case id)}
186187
#{"en-US"})))))
@@ -193,7 +194,7 @@
193194
(is
194195
(not-empty
195196
(get-in (lrs/get-statements lrs
196-
{}
197+
ctx-103
197198
auth-id
198199
{:registration (cs/upper-case reg)}
199200
#{"en-US"})
@@ -204,23 +205,23 @@
204205
id (get s "id")
205206
lrs (doto (mem/new-lrs {:statements-result-max s-count})
206207
(lrs/store-statements
207-
{}
208+
ctx-103
208209
auth-id
209210
[(-> s
210211
(update "id" cs/upper-case)
211212
(update-in ["context" "registration"] cs/upper-case))]
212213
[]))]
213214
(is (:statement (lrs/get-statements
214215
lrs
215-
{}
216+
ctx-103
216217
auth-id
217218
{:statementId id}
218219
#{"en-US"})))
219220
;; This test will pass even w/o normalized IDs, but it makes sure we
220221
;; don't screw up the rel index
221222
(is (not-empty (get-in (lrs/get-statements
222223
lrs
223-
{}
224+
ctx-103
224225
auth-id
225226
{:verb (get-in s ["verb" "id"])}
226227
#{"en-US"})
@@ -229,7 +230,7 @@
229230
(testing "reg index"
230231
(is (not-empty (get-in (lrs/get-statements
231232
lrs
232-
{}
233+
ctx-103
233234
auth-id
234235
{:registration (get-in s ["context"
235236
"registration"])}
@@ -239,8 +240,18 @@
239240
(testing "original case is preserved"
240241
(is (= (cs/upper-case id)
241242
(get-in (lrs/get-statements lrs
242-
{}
243+
ctx-103
243244
auth-id
244245
{:statementId id}
245246
#{"en-US"})
246-
[:statement "id"]))))))))
247+
[:statement "id"]))))
248+
;; impl test
249+
(testing "version is 1.0.0"
250+
(is (= "1.0.0"
251+
(get-in (lrs/get-statements
252+
lrs
253+
ctx-103
254+
auth-id
255+
{:statementId id}
256+
#{"en-US"})
257+
[:statement "version"]))))))))

0 commit comments

Comments
 (0)