Skip to content

Commit

Permalink
LRS-72 added attachment normalization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed May 12, 2022
1 parent 02df36c commit cf53077
Showing 1 changed file with 80 additions and 8 deletions.
88 changes: 80 additions & 8 deletions src/test/lrsql/lrs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,48 @@
:length 27
:sha2 "495395e777cd98da653df9615d09c0fd6bb2f8d4788394cd53c56a3bfdcd848a"})

(def stmt-5
{"id" "00000000-0000-4000-8000-000000000005"
"actor" {"mbox" "mailto:sample.foo@example.com"
"objectType" "Agent"}
"verb" {"id" "http://adlnet.gov/expapi/verbs/answered"
"display" {"en-US" "answered"}}
"object" {"id" "http://www.example.com/tincan/activities/multipart"}
"attachments" [{"usageType" "http://example.com/attachment-usage/test"
"display" {"en-US" "A test attachment"}
"description" {"en-US" "A test attachment (description)"}
"contentType" "text/plain"
"length" 27
"sha2" "495395e777cd98da653df9615d09c0fd6bb2f8d4788394cd53c56a3bfdcd848a"}
{"usageType" "http://example.com/attachment-usage/test"
"display" {"en-US" "A test attachment"}
"description" {"en-US" "A test attachment (description)"}
"contentType" "text/plain"
"length" 33
"sha2" "7063d0a4cfa93373753ad2f5a6ffcf684559fb1df3c2f0473a14ece7d4edb06a"}
{"usageType" "http://example.com/attachment-usage/test"
"display" {"en-US" "A test attachment"}
"description" {"en-US" "A test attachment (description)"}
"contentType" "text/plain"
"length" 33
"sha2" "7063d0a4cfa93373753ad2f5a6ffcf684559fb1df3c2f0473a14ece7d4edb06a"}]})

(def stmt-5-attach
{:content (.getBytes "here is a simple attachment")
:contentType "text/plain"
:length 33
:sha2 "7063d0a4cfa93373753ad2f5a6ffcf684559fb1df3c2f0473a14ece7d4edb06a"})

(defn- string-result-attachment-content
[get-ss-result]
(update get-ss-result
:attachments
(fn [atts]
(mapv
(fn [att]
(update att :content #(String. %)))
atts))))

(deftest test-statement-fns
(let [sys (support/test-system)
sys' (component/start sys)
Expand Down Expand Up @@ -331,10 +373,7 @@
auth-ident
{:activity act-4 :attachments true}
#{})
(update-in [:attachments]
vec)
(update-in [:attachments 0 :content]
#(String. %))))))
string-result-attachment-content))))

(testing "(single)"
(is (= {:statement stmt-4
Expand All @@ -343,10 +382,7 @@
auth-ident
{:statementId (get stmt-4 "id") :attachments true}
#{})
(update-in [:attachments]
vec)
(update-in [:attachments 0 :content]
#(String. %)))))))
string-result-attachment-content)))))

(testing "agent query"
(is (= {:person
Expand All @@ -367,6 +403,42 @@
(component/stop sys')
(support/unstrument-lrsql)))

(deftest attachment-normalization-test
(let [sys (support/test-system)
sys' (component/start sys)
lrs (-> sys' :lrs)
id-4 (get stmt-4 "id")
id-5 (get stmt-5 "id")]

(testing "accepts normalized attachments"
(is (= {:statement-ids [id-4
id-5]}
(lrsp/-store-statements
;; stmt-5 references stmt-4-attach AND stmt-5-attach
lrs auth-ident [stmt-4 stmt-5] [stmt-4-attach stmt-5-attach]))))

(testing "returns normalized attachments"
(testing "(multiple)"
(is (= {:statement-result {:statements [stmt-5 stmt-4] :more ""}
:attachments [(update stmt-5-attach :content #(String. %))
(update stmt-4-attach :content #(String. %))]}
(-> (get-ss lrs
auth-ident
{:attachments true}
#{})
string-result-attachment-content))))
(testing "(single)"
(is (= {:statement stmt-5
:attachments [(update stmt-5-attach :content #(String. %))
(update stmt-4-attach :content #(String. %))]}
(-> (get-ss lrs
auth-ident
{:statementId id-5 :attachments true}
#{})
string-result-attachment-content)))))
(component/stop sys')
(support/unstrument-lrsql)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Statement Ref Tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down

0 comments on commit cf53077

Please sign in to comment.