Just a quick note about testing the body_reader that took me a while to figure out. I had a hard time just getting the custom body reader to run in controller tests until I realized the following:
- You must set a
content-typeheader, and - You have to send your post request as a string and not a map. Sending as a map will bypass the body reader.
My test ended up looking something like:
test "invalid hmac signature", %{conn: conn} do
conn =
conn
|> Plug.Conn.put_req_header("content-type", "application/json")
|> post(~p"/api/webhooks", "{}")
assert response(conn, 400) == "Invalid signature"
end
Hope that helps someone stop banging their head on the desk as much as I did!






















