From 21c11fd6dc1689b6c80dd8b69759145cbc0cf5f0 Mon Sep 17 00:00:00 2001 From: Leandro Doctors Date: Thu, 21 Nov 2024 13:30:15 +0100 Subject: [PATCH] Add regression tests for JSON and binary (WIP) --- .../blaze/middleware/fhir/output_test.clj | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/rest-util/test/blaze/middleware/fhir/output_test.clj b/modules/rest-util/test/blaze/middleware/fhir/output_test.clj index df6a481bd..096adc7b9 100644 --- a/modules/rest-util/test/blaze/middleware/fhir/output_test.clj +++ b/modules/rest-util/test/blaze/middleware/fhir/output_test.clj @@ -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))) @@ -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)] @@ -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"}}))))