pedestal

asilverman 2019-02-16T00:34:17.026200Z

Thank you so much, I tried this approach but in my case since our service is wrapped inside a component I ended up creating a macro I am using as a fixture to exercise the response-for function

(defmacro with-mock-ds-system
  [[sym ds-factory] & body]
  ;; Create a system map with a mock datastore and a mock auth-checker, set ::http/join == false so
  ;; that the system doesn't block execution.
  `(let [temp# ~ds-factory]
     ;; Store a reference to this system, perhaps unnecessary but done for the sake
     ;; of future debuggability.
     (reset! mock-svc (component/start-system (service/consent-service
                                                (env/get-api-config)
                                                (create-mock-auth-checker (env/get-api-config))
                                                {:type   :mockstore
                                                 :config temp#}
                                                {:env         :dev
                                                 ::http/join? false})))
     ;; Pull the servlet function that is used for testing out of the newly created system.
     (let [~sym (get-in @mock-svc [:consent :service ::http/service-fn])]
       (try
         ~@body
         ;; Shutdown system.
         (finally
           (component/stop-system @mock-svc)
           (reset! mock-svc nil))))))

2019-02-16T12:07:41.028200Z

And maybe an integration testing would be to compose "unit tests". for example - List resources: empty - Create resource: return resource - List resource: list with the created resource - Update the resource: return the updated resource ...and so on. Is this the idea of an integration testing?

2019-02-17T16:51:16.029500Z

I think that’s consistent with integration testing. In my experience, the term integration testing has been used to describe end-to-end tests which exercise the system in the context of backing infrastructure/dependencies (i.e., real database, externally deployed services, etc…)

2019-02-16T12:19:34.029200Z

For the unit test, we could also use let to get the response and use it to multiple "assertions"

(let [response (response-for service
                             :post "/foo"
                             :headers {"Content-Type" "application/json"}
                             :body "{\"foo\":\"bar\"}")]
  (is (= 200 (:status response)))
  (is (= {"foo": "bar"} (:body response))))