Skip to content

Commit 8f76505

Browse files
authored
Merge pull request #421 from yetanalytics/post-empty-list
[LRS-83] POST with empty list
2 parents c9a6cfa + 1c7f3f7 commit 8f76505

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

deps.edn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
;; Yet Analytics deps
4747

4848
com.yetanalytics/lrs
49-
{:mvn/version "1.2.19"
49+
{:mvn/version "1.2.21"
5050
:exclusions [org.clojure/clojure
5151
org.clojure/clojurescript
5252
com.yetanalytics/xapi-schema]}
5353

5454
com.yetanalytics/xapi-schema
55-
{:mvn/version "1.3.0"
55+
{:mvn/version "1.4.0"
5656
:exclusions [org.clojure/clojure
5757
org.clojure/clojurescript]}
5858
com.yetanalytics/colossal-squuid

src/main/lrsql/spec/statement.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158

159159
(def stmt-input-attachments-spec*
160160
(s/cat :statement-inputs
161-
(s/coll-of insert-statement-input-spec :min-count 1 :gen-max 5)
161+
(s/coll-of insert-statement-input-spec :gen-max 5)
162162
:attachments
163163
(s/coll-of ::ss/attachment :gen-max 2)))
164164

src/test/lrsql/lrs_test.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,15 @@
212212
act-1 (get-in stmt-1 ["object" "id"])
213213
act-4 (get-in stmt-4 ["object" "id"])]
214214

215-
(testing "statement insertions"
215+
(testing "empty statement insertions"
216+
(is (= {:statement-ids []}
217+
(lrsp/-store-statements lrs auth-ident [] [])))
218+
(is (= {:statement-result {:statements []
219+
:more ""}
220+
:attachments []}
221+
(get-ss lrs auth-ident {:limit 50} #{}))))
222+
223+
(testing "statement insertions"
216224
(is (= {:statement-ids [id-0]}
217225
(lrsp/-store-statements lrs auth-ident [stmt-0] [])))
218226
(is (= {:statement-ids [id-1 id-2 id-3]}

src/test/lrsql/scope_test.clj

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,34 @@
3636
(def stmt-1
3737
(assoc stmt-0 "id" "00000000-0000-4000-8000-000000000001"))
3838

39+
(def stmt-2
40+
(assoc stmt-0 "id" "00000000-0000-4000-8000-000000000002"))
41+
3942
(def stmt-id-0
4043
(get stmt-0 "id"))
4144

4245
(def stmt-id-1
4346
(get stmt-1 "id"))
4447

48+
(def stmt-id-2
49+
(get stmt-2 "id"))
50+
4551
(def stmt-body-0
4652
(u/write-json-str stmt-0))
4753

4854
(def stmt-body-1
4955
(u/write-json-str stmt-1))
5056

57+
;; These test constants are to test when statement arrays are POST'd to the LRS.
58+
;; For some reason, these are not test cases in the ADL conformance tests, and
59+
;; adding a new namespace just for a couple POST requests would be overkill,
60+
;; so we just put them here.
61+
(def stmt-body-empty-array
62+
(u/write-json-str []))
63+
64+
(def stmt-body-array
65+
(u/write-json-str [stmt-2]))
66+
5167
;; /agents
5268

5369
(def agent-endpoint
@@ -228,7 +244,15 @@
228244
(is (= ~(if statement-write? 200 403)
229245
(try-post ~stmt-endpoint
230246
~'creds
231-
{:body ~stmt-body-0}))))
247+
{:body ~stmt-body-0})))
248+
(is (= ~(if statement-write? 200 403)
249+
(try-post ~stmt-endpoint
250+
~'creds
251+
{:body ~stmt-body-empty-array})))
252+
(is (= ~(if statement-write? 200 403)
253+
(try-post ~stmt-endpoint
254+
~'creds
255+
{:body ~stmt-body-array}))))
232256
(testing "PUT"
233257
(is (= ~(if statement-write? 204 403)
234258
(try-put ~stmt-endpoint
@@ -489,7 +513,11 @@
489513
(is (= 200
490514
(try-post stmt-endpoint creds-1 {:body stmt-body-0})))
491515
(is (= 200
492-
(try-post stmt-endpoint creds-2 {:body stmt-body-1}))))
516+
(try-post stmt-endpoint creds-2 {:body stmt-body-1})))
517+
(is (= 200
518+
(try-post stmt-endpoint creds-1 {:body stmt-body-empty-array})))
519+
(is (= 200
520+
(try-post stmt-endpoint creds-2 {:body stmt-body-array}))))
493521
(testing "/statements GET with correct authority"
494522
(is (= 200
495523
(try-get stmt-endpoint
@@ -498,7 +526,11 @@
498526
(is (= 200
499527
(try-get stmt-endpoint
500528
creds-2
501-
{:params {:statementId stmt-id-1}}))))
529+
{:params {:statementId stmt-id-1}})))
530+
(is (= 200
531+
(try-get stmt-endpoint
532+
creds-2
533+
{:params {:statementId stmt-id-2}}))))
502534
(testing "/statements HEAD with correct authority"
503535
(is (= 200
504536
(try-head stmt-endpoint
@@ -507,14 +539,22 @@
507539
(is (= 200
508540
(try-head stmt-endpoint
509541
creds-2
510-
{:params {:statementId stmt-id-1}}))))
542+
{:params {:statementId stmt-id-1}})))
543+
(is (= 200
544+
(try-head stmt-endpoint
545+
creds-2
546+
{:params {:statementId stmt-id-2}}))))
511547
;; Treated as 404 Not Found as the statement does not exist within the
512548
;; scope of the authority, rather than a blanket 403 Forbidden.
513549
(testing "/statements GET with wrong authority"
514550
(is (= 404
515551
(try-get stmt-endpoint
516552
creds-1
517553
{:params {:statementId stmt-id-1}})))
554+
(is (= 404
555+
(try-get stmt-endpoint
556+
creds-1
557+
{:params {:statementId stmt-id-2}})))
518558
(is (= 404
519559
(try-get stmt-endpoint
520560
creds-2
@@ -524,6 +564,10 @@
524564
(try-head stmt-endpoint
525565
creds-1
526566
{:params {:statementId stmt-id-1}})))
567+
(is (= 404
568+
(try-head stmt-endpoint
569+
creds-1
570+
{:params {:statementId stmt-id-2}})))
527571
(is (= 404
528572
(try-head stmt-endpoint
529573
creds-2

0 commit comments

Comments
 (0)