In my tests, I'm hitting the router with json for each route, and only json is accepted by Plug.parser. This works fine, except for tests using the delete method, which always fail with Unsupported content type: multipart/mixed. I'm sending an empty body with the delete request with my application/json as content-type in the headers, but I think the _method parameter is causing it to be rejected as wrong content type- although this does not happen with put method which should require _method to be added to request body also.
test "inactivate" do
{id, token} = register
response = Myapp.Router.call(conn(:delete, "/api/manager/tenants/" <> id,
[], headers: [{"content-type", "application/json"}, {"token", token}] ) |> Plug.Conn.fetch_params(), @opts)
assert response.status == 200
end
when hitting the same delete routes with httprequester, they work fine and are not stopped by plug parser. Does Router.call handle http requests differently in tests?
MyApp.ConnCase
. You should use that when running Controller tests. It provides conveniences for testing Controllers. – Gjaldon""
but that will likely fail because it is not valid JSON. Or send "{}" or do not send anything (nil). – José Valim