Fork me on GitHub
#reitit
<
2022-11-30
>
manderson18:11:39

I'm using reitit.ring.middleware.muuntaja/format-request-middleware (along with negotiate and response) with the default options and it seems to have different behavior when calling it via an HTTP request in a running server vs just using the handler as a function on a ring-mock request in my unit tests. When I send a request with invalid JSON the server implementation does as expected and fails it, getting caught by my exception middleware, and returns a 400. However, the unit test / REPL implementation with ring-mock does not fail and passes on the invalid JSON as a string where it fails in coercion. Everything is identical between the two as far as I can tell... Any ideas on why this might be the case?

valtteri19:11:42

Are you setting Content-Type with ring-mock?

manderson19:11:06

Yeah, I'm using this:

(-> (ring-mock/request :post path)
      (ring-mock/body (if (string? body) body (json/write-value-as-string body)))
      (ring-mock/header :content-type "application/json"))

valtteri19:11:21

Yep, looks good. That was my first guess. And I don’t have better guesses but something being different in the request. Also worth checking if there’s anything interesting done when the real server is started

manderson19:11:15

Thanks for the help. Yeah, I've been diffing the two and can't seem to find any differences, thus the head desk 🙂 I'll keep digging

valtteri20:11:09

Yep, without seeing more code I can only help with debugging. 🙂 Try to start from the minimum and add stuff one by one

valtteri20:11:11

Also might be worth checking out ring-mock sources for possible surprises. It’s minimal and very readable.

gratitude-thank-you 1