compojure-api icon indicating copy to clipboard operation
compojure-api copied to clipboard

expose route schemas for (test) clients

Open johnmcconnell opened this issue 7 years ago • 2 comments

Currently there is an API which coerces a response to the json content. It would be useful for testing if the reverse mapping is also provided by default.

Example:

(deftext something-to-test
  (let [entity (generate schema)
          _    (db/insert! entity)
          response (app request)]
     (is (ok? response))
     (when (ok? response) (is (= (-> response (->schema-entity schema)) entity)))))

johnmcconnell avatar May 24 '17 03:05 johnmcconnell

If I understood correctly, this requires two things:

  1. response should contain information about the encoded format (it does already)
  2. response should contain the response schema (could be done, but just locally, not over http)

also, if there are custom options for the used format (e.g. JSON encoder/decoder options), they should available for the test. This can be done by using a separate Muuntaja instance.

One option (we have been using) is to use EDN/Transit in tests -> data is transferred as-is, no need to run json-coersion in tests. Would this be feasible in your case?

ikitommi avatar May 26 '17 13:05 ikitommi

I'll take a look at that, although it doesn't appear to be quite what I am looking for. I'll look at it more in detail soon

johnmcconnell avatar Jun 02 '17 07:06 johnmcconnell