 
 (deftest get-visit-id-does-not-exist
   (testing "GET /visits/<someid> (nonexistant entity)"
-    (let [visits (:visits cts/*system*)
-          handler (make-handler (vhosts-model [:* (sut/visit-routes visits)]))
-          request (mock/request :get "/visits/9999")
-          response @(handler request)]
+    (let [request (mock/request :get "/visits/9999")
+          response @(*handler* request)]
       (is (= 404 (:status response))))))
 
 (deftest get-visits-id-exists
   (testing "GET /visits/<someid> (existing entry)"
-    (let [visits (:visits cts/*system*)
-          visit-routes (vhosts-model [:* (sut/visit-routes visits)])
-          create-handler (make-handler visit-routes)
-          data example-visit
+    (let [data example-visit
           create-request (mock/json-body (mock/request :post "/visits") data)
-          create-response @(create-handler create-request)
-          get-handler (make-handler visit-routes)
+          create-response @(*handler* create-request)
           get-request (mock/request :get (get-in create-response [:headers "location"]))
           get-response (-> get-request
-                           get-handler
+                           *handler*
                            deref
                            :body
                            bs/to-string


(deftest update-visits-entry-exists
  (testing "PUT /visits/<id> (<id> existed already)"
    (let [visits (:visits cts/*system*)
          visit-routes (vhosts-model [:* (sut/visit-routes visits)])
          handler (make-handler visit-routes)
          create-request (mock/json-body (mock/request :post "/visits") example-visit)
          location (get-in @(handler create-request) [:headers "location"])
          put-body (assoc example-visit :cafe_name "Updated Café")
          put-request (mock/json-body (mock/request :put location) put-body)
          put-response @(handler put-request)]
      (is (= 204 (:status put-response))))))

(deftest update-visits-entry-does-not-exist
  (testing "PUT /visits/<id> (<id> doesn't exist)"
    (let [visits (:visits cts/*system*)
          visit-routes (vhosts-model [:* (sut/visit-routes visits)])
          put-handler (make-handler visit-routes)
          put-body (-> example-visit (assoc :id 0) (assoc :cafe_name "Updated Café"))
          put-request (mock/json-body (mock/request :put "/visits/0") put-body)
          put-response @(put-handler put-request)]
      (is (= 404 (:status put-response))))))

(deftest update-visits-invalid-data


(deftest delete-visits-id-exists
    (testing "DELETE /visits/<someid> (existing entry)"
      (let [create-request (mock/json-body (mock/request :post "/visits") example-visit)
            create-response @(*handler* create-request)
            location (get-in create-response [:headers "location"])
            delete-request (mock/request :delete location)
            delete-response @(*handler* delete-request)
            get-request (mock/request :get location)
            get-response @(*handler* get-request)]
        (is (= 204 (:status delete-response)))
        (is (= 404 (:status get-response))))))

(deftest delete-visits-id-does-not-exist
  (testing "DELETE /visits/<id> (<id> doesn't exist)"
    (let [delete-request (mock/request :delete "/visits/0")
          delete-response @(*handler* delete-request)]
      (is (= 204 (:status delete-response))))))
