Hi, I am starting with Plug.Conn and Tests.
Just for learning, my app have the next route:
post "/ping" do
{:ok, str} = Jason.encode(conn.body_params)
send_resp(conn|> put_resp_content_type("application/json"), 200,str)
end
Then give a try with curl:
curl -X POST http://localhost:5000/ping -d ‘{“key”: “value”}’ -H “content-type: application/json”
and has spected, receive the same json.
Now want to use Test:
test "ping json" do
json =%{ username: "demonds",password: "supersecret"}
conn=conn(:post, "http://localhost:5000/ping",json)|> put_req_header("content-type", "application/json")
IO.inspect(conn.resp_body, label: "resp_body:")
IO.inspect(conn, label: "conn:")
end
Execute: mix test
But the conn.resp_body is nil and also the conn.status is nil and not 200?
Sound like the post is not executed.
What command is missing ?