-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clinic: add integration test for create patient endpoint; minor refactor
- Loading branch information
1 parent
30b47a5
commit eb376b2
Showing
14 changed files
with
159 additions
and
52 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
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
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
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
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,20 @@ | ||
(ns clinic.factory | ||
(:require [clojure.spec.gen.alpha :as gen] | ||
[clojure.spec.alpha :as s] | ||
[clinic.service.patient :as patient])) | ||
|
||
(defn- generate-date [] | ||
(String/format "%04d-%02d-%02d" | ||
(into-array [(+ 1970 (rand-int 52)) | ||
(inc (rand-int 12)) | ||
(inc (rand-int 28))]))) | ||
|
||
(defn- with-generator-fn [gen-fn] | ||
(-> (fn [& _] (gen-fn)) | ||
(gen/fmap (gen/return nil)) | ||
(constantly))) | ||
|
||
(defn create-params [] | ||
(->> {::patient/birth-date (with-generator-fn generate-date)} | ||
(s/gen ::patient/create-params) | ||
(gen/generate))) |
41 changes: 41 additions & 0 deletions
41
clinic/test/clj/clinic/routes/patient_integration_test.clj
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,41 @@ | ||
(ns clinic.routes.patient-integration-test | ||
(:require [clinic.factory :as factory] | ||
[clinic.routes.core :as routes] | ||
[clinic.test-utils :as tu] | ||
[clojure.test :refer [deftest is testing use-fixtures]] | ||
[ring.mock.request :as mr] | ||
[cheshire.core :as json])) | ||
|
||
(defn- create-patient-request [body] | ||
(-> (mr/request :post "/api/v1/patients/") | ||
(mr/json-body body))) | ||
|
||
(use-fixtures :once tu/load-config-fixture) | ||
(use-fixtures :each tu/expunge-fhir-data-fixture) | ||
|
||
(deftest create-patient-test | ||
(testing "with invalid request body" | ||
(doseq [missing-field [:first-name :last-name :birth-date :gender]] | ||
(is (= 400 (-> (factory/create-params) | ||
(dissoc missing-field) | ||
(create-patient-request) | ||
(routes/handler) | ||
(get :status)))))) | ||
|
||
(testing "with valid request body" | ||
(let [params (factory/create-params) | ||
{status :status | ||
body :body} (-> params | ||
(create-patient-request) | ||
(routes/handler) | ||
(update :body json/parse-string true))] | ||
(is (= 201 status)) | ||
(is (contains? body :id)) | ||
(is (contains? body :mrn)) | ||
(is (= (params :first-name) (body :first-name))) | ||
(is (= (params :last-name) (body :last-name))) | ||
(is (= (params :birth-date) (body :birth-date))) | ||
(is (= (params :gender) (body :gender))) | ||
(is (= (params :marital-status) (body :marital-status))) | ||
(is (= (params :phone) (body :phone))) | ||
(is (= (params :email) (body :email)))))) |
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
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,25 @@ | ||
(ns clinic.test-utils | ||
(:require [cheshire.core :as json] | ||
[clj-http.client :as http] | ||
[clinic.config :as config] | ||
[mount.core :as mount])) | ||
|
||
(defn load-config-fixture [f] | ||
(mount/start #'config/config) | ||
(f) | ||
(mount/stop)) | ||
|
||
(defn expunge-fhir-data! [server-url] | ||
(-> server-url | ||
(str "/$expunge") | ||
(http/post {:headers {"Content-Type" "application/fhir+json"} | ||
:body (json/generate-string {:resourceType "Parameters" | ||
:parameter [{:name "expungeEverything" | ||
:valueBoolean true}]}) | ||
:throw-exceptions false}))) | ||
|
||
(defn expunge-fhir-data-fixture [f] | ||
(-> :fhir-server-base-url | ||
(config/get-value) | ||
(expunge-fhir-data!)) | ||
(f)) |