Skip to content

Commit

Permalink
Add regression tests for JSON and binary (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
allentiak committed Nov 21, 2024
1 parent f315918 commit 21c11fd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions modules/rest-util/test/blaze/middleware/fhir/output_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
(defn- resource-handler-500 [resource]
(common-handler-500 wrap-output resource))

(defn- binary-resource-handler-500 [resource]
(common-handler-500 wrap-binary-output resource))

(defn- parse-json [body]
(fhir-spec/conform-json (fhir-spec/parse-json body)))

Expand Down Expand Up @@ -113,7 +116,14 @@
:query-params {"_format" format}})
:status := 200
[:headers "Content-Type"] := content-type
[:body parse-json] := {:fhir/type :fhir/Patient :id "0"}))))
[:body parse-json] := {:fhir/type :fhir/Patient :id "0"})))

(testing "failing JSON emit"
(given (call (resource-handler-500 {:fhir/type :fhir/Patient :id "0" :gender #fhir/code"foo\u001Ebar"}) {:headers {"accept" "application/fhir+json"}})
:status := 500
[:headers "Content-Type"] := "application/fhir+json;charset=utf-8"
[:body parse-json :fhir/type] := :fhir/OperationOutcome
[:body parse-json :issue 0 :diagnostics] := "Invalid white space character (0x1e) in text to output (in xml 1.1, could output as a character entity)")))

(defn- parse-xml [body]
(with-open [reader (io/reader body)]
Expand Down Expand Up @@ -216,7 +226,14 @@
(given (call binary-resource-handler-no-body {:headers {"accept" "text/plain"}})
:status := 200
[:headers "Content-Type"] := nil
:body := nil)))
:body := nil))

(testing "failing binary emit"
(given (call (binary-resource-handler-500 {:fhir/type :fhir/Patient :id "0" :gender #fhir/code"foo\u001Ebar"}) {:headers {"accept" "text/plain"}})
:status := 500
[:headers "Content-Type"] := "application/fhir+xml;charset=utf-8"
[:body parse-xml :fhir/type] := :fhir/OperationOutcome
[:body parse-xml :issue 0 :diagnostics] := "Invalid white space character (0x1e) in text to output (in xml 1.1, could output as a character entity)")))

(deftest not-acceptable-test
(is (nil? (call resource-handler-200 {:headers {"accept" "text/plain"}}))))

0 comments on commit 21c11fd

Please sign in to comment.