-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--105423a5219f5a63362a375ba7a64a8f234da19c7d01e56800c3c64b26bb2fa0 | ||
Content-Type:application/json | ||
|
||
{ | ||
"actor": { | ||
"mbox": "mailto:sample.agent@example.com", | ||
"name": "Sample Agent", | ||
"objectType": "Agent" | ||
}, | ||
"verb": { | ||
"id": "http://adlnet.gov/expapi/verbs/answered", | ||
"display": { | ||
"en-US": "answered" | ||
} | ||
}, | ||
"object": { | ||
"id": "http://www.example.com/tincan/activities/multipart", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { | ||
"en-US": "Multi Part Activity" | ||
}, | ||
"description": { | ||
"en-US": "Multi Part Activity Description" | ||
} | ||
} | ||
}, | ||
"attachments": [ | ||
{ | ||
"usageType": "http://example.com/attachment-usage/test", | ||
"display": { "en-US": "A test attachment" }, | ||
"description": { "en-US": "A test attachment (description)" }, | ||
"contentType": "text/plain; charset=ascii", | ||
"length": 27, | ||
"sha2": "495395e777cd98da653df9615d09c0fd6bb2f8d4788394cd53c56a3bfdcd848a" | ||
} | ||
] | ||
} | ||
--105423a5219f5a63362a375ba7a64a8f234da19c7d01e56800c3c64b26bb2fa0 | ||
Content-Type:text/plain | ||
Content-Transfer-Encoding:binary | ||
X-Experience-API-Hash:495395e777cd98da653df9615d09c0fd6bb2f8d4788394cd53c56a3bfdcd848a | ||
|
||
here is a simple attachment | ||
--105423a5219f5a63362a375ba7a64a8f234da19c7d01e56800c3c64b26bb2fa0-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(ns com.yetanalytics.lrs.scan-test | ||
(:require [clojure.test :refer [deftest testing is use-fixtures]] | ||
[babashka.curl :as curl] | ||
[io.pedestal.http :as http] | ||
[com.yetanalytics.test-support :as support])) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Tests | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
|
||
(def attachment-post-params | ||
{:basic-auth ["username" "password"] | ||
:headers | ||
{"X-Experience-API-Version" "1.0.3" | ||
"Content-Type" | ||
"multipart/mixed; boundary=105423a5219f5a63362a375ba7a64a8f234da19c7d01e56800c3c64b26bb2fa0"} | ||
:body (slurp "dev-resources/attachments/attachment_post_body.txt") | ||
:throw false}) | ||
|
||
(def doc-post-params | ||
{:basic-auth ["username" "password"] | ||
:headers {"X-Experience-API-Version" "1.0.3"} | ||
:query-params | ||
{"activityId" "http://www.example.com/activityId/hashset" | ||
"agent" | ||
"{\"objectType\":\"Agent\",\"account\":{\"homePage\":\"http://www.example.com/agentId/1\",\"name\":\"Rick James\"}}" | ||
"stateId" "f8128f68-74e2-4951-8c5f-ef7cce73b4ff"} | ||
:body "I'm a little teapot" | ||
:throw false}) | ||
|
||
(deftest scan-test | ||
(testing "File/Document Scanning" | ||
;; Stub out a scanner that always fails | ||
(testing "Failure" | ||
(let [server (support/test-server | ||
:route-opts | ||
{:file-scanner | ||
(fn [in] | ||
(slurp in) | ||
{:message "Scan Fail!"})})] | ||
(try | ||
(http/start server) | ||
(testing "Attachment" | ||
(is (= {:status 400 | ||
:body "{\"error\":{\"message\":\"Attachment scan failed, Errors: Scan Fail!\"}}"} | ||
(select-keys | ||
(curl/post | ||
"http://localhost:8080/xapi/statements" | ||
attachment-post-params) | ||
[:body :status])))) | ||
(testing "Document" | ||
(is (= {:status 400 | ||
:body "{\"error\":{\"message\":\"Document scan failed, Error: Scan Fail!\"}}"} | ||
(select-keys | ||
(curl/post | ||
"http://localhost:8080/xapi/activities/state" | ||
doc-post-params) | ||
[:body :status])))) | ||
(finally | ||
(http/stop server))))) | ||
(testing "Success" | ||
(let [server (support/test-server)] | ||
(try | ||
(http/start server) | ||
(testing "Attachment" | ||
(is (= 200 | ||
(:status | ||
(curl/post | ||
"http://localhost:8080/xapi/statements" | ||
attachment-post-params))))) | ||
(testing "Document" | ||
(is (= 204 | ||
(:status | ||
(curl/post | ||
"http://localhost:8080/xapi/activities/state" | ||
doc-post-params))))) | ||
(finally | ||
(http/stop server))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters