Skip to content

Commit

Permalink
Merge pull request #421 from yetanalytics/post-empty-list
Browse files Browse the repository at this point in the history
[LRS-83] POST with empty list
  • Loading branch information
kelvinqian00 authored Oct 7, 2024
2 parents c9a6cfa + 1c7f3f7 commit 8f76505
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
;; Yet Analytics deps

com.yetanalytics/lrs
{:mvn/version "1.2.19"
{:mvn/version "1.2.21"
:exclusions [org.clojure/clojure
org.clojure/clojurescript
com.yetanalytics/xapi-schema]}

com.yetanalytics/xapi-schema
{:mvn/version "1.3.0"
{:mvn/version "1.4.0"
:exclusions [org.clojure/clojure
org.clojure/clojurescript]}
com.yetanalytics/colossal-squuid
Expand Down
2 changes: 1 addition & 1 deletion src/main/lrsql/spec/statement.clj
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@

(def stmt-input-attachments-spec*
(s/cat :statement-inputs
(s/coll-of insert-statement-input-spec :min-count 1 :gen-max 5)
(s/coll-of insert-statement-input-spec :gen-max 5)
:attachments
(s/coll-of ::ss/attachment :gen-max 2)))

Expand Down
10 changes: 9 additions & 1 deletion src/test/lrsql/lrs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,15 @@
act-1 (get-in stmt-1 ["object" "id"])
act-4 (get-in stmt-4 ["object" "id"])]

(testing "statement insertions"
(testing "empty statement insertions"
(is (= {:statement-ids []}
(lrsp/-store-statements lrs auth-ident [] [])))
(is (= {:statement-result {:statements []
:more ""}
:attachments []}
(get-ss lrs auth-ident {:limit 50} #{}))))

(testing "statement insertions"
(is (= {:statement-ids [id-0]}
(lrsp/-store-statements lrs auth-ident [stmt-0] [])))
(is (= {:statement-ids [id-1 id-2 id-3]}
Expand Down
52 changes: 48 additions & 4 deletions src/test/lrsql/scope_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,34 @@
(def stmt-1
(assoc stmt-0 "id" "00000000-0000-4000-8000-000000000001"))

(def stmt-2
(assoc stmt-0 "id" "00000000-0000-4000-8000-000000000002"))

(def stmt-id-0
(get stmt-0 "id"))

(def stmt-id-1
(get stmt-1 "id"))

(def stmt-id-2
(get stmt-2 "id"))

(def stmt-body-0
(u/write-json-str stmt-0))

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

;; These test constants are to test when statement arrays are POST'd to the LRS.
;; For some reason, these are not test cases in the ADL conformance tests, and
;; adding a new namespace just for a couple POST requests would be overkill,
;; so we just put them here.
(def stmt-body-empty-array
(u/write-json-str []))

(def stmt-body-array
(u/write-json-str [stmt-2]))

;; /agents

(def agent-endpoint
Expand Down Expand Up @@ -228,7 +244,15 @@
(is (= ~(if statement-write? 200 403)
(try-post ~stmt-endpoint
~'creds
{:body ~stmt-body-0}))))
{:body ~stmt-body-0})))
(is (= ~(if statement-write? 200 403)
(try-post ~stmt-endpoint
~'creds
{:body ~stmt-body-empty-array})))
(is (= ~(if statement-write? 200 403)
(try-post ~stmt-endpoint
~'creds
{:body ~stmt-body-array}))))
(testing "PUT"
(is (= ~(if statement-write? 204 403)
(try-put ~stmt-endpoint
Expand Down Expand Up @@ -489,7 +513,11 @@
(is (= 200
(try-post stmt-endpoint creds-1 {:body stmt-body-0})))
(is (= 200
(try-post stmt-endpoint creds-2 {:body stmt-body-1}))))
(try-post stmt-endpoint creds-2 {:body stmt-body-1})))
(is (= 200
(try-post stmt-endpoint creds-1 {:body stmt-body-empty-array})))
(is (= 200
(try-post stmt-endpoint creds-2 {:body stmt-body-array}))))
(testing "/statements GET with correct authority"
(is (= 200
(try-get stmt-endpoint
Expand All @@ -498,7 +526,11 @@
(is (= 200
(try-get stmt-endpoint
creds-2
{:params {:statementId stmt-id-1}}))))
{:params {:statementId stmt-id-1}})))
(is (= 200
(try-get stmt-endpoint
creds-2
{:params {:statementId stmt-id-2}}))))
(testing "/statements HEAD with correct authority"
(is (= 200
(try-head stmt-endpoint
Expand All @@ -507,14 +539,22 @@
(is (= 200
(try-head stmt-endpoint
creds-2
{:params {:statementId stmt-id-1}}))))
{:params {:statementId stmt-id-1}})))
(is (= 200
(try-head stmt-endpoint
creds-2
{:params {:statementId stmt-id-2}}))))
;; Treated as 404 Not Found as the statement does not exist within the
;; scope of the authority, rather than a blanket 403 Forbidden.
(testing "/statements GET with wrong authority"
(is (= 404
(try-get stmt-endpoint
creds-1
{:params {:statementId stmt-id-1}})))
(is (= 404
(try-get stmt-endpoint
creds-1
{:params {:statementId stmt-id-2}})))
(is (= 404
(try-get stmt-endpoint
creds-2
Expand All @@ -524,6 +564,10 @@
(try-head stmt-endpoint
creds-1
{:params {:statementId stmt-id-1}})))
(is (= 404
(try-head stmt-endpoint
creds-1
{:params {:statementId stmt-id-2}})))
(is (= 404
(try-head stmt-endpoint
creds-2
Expand Down

0 comments on commit 8f76505

Please sign in to comment.