我有这个简单的测试:
test "Welcomes Github" do
json = Jason.encode!(%{repository: %{full_name: "test/test"}})
conn =
conn(:post, "/", json)
|> Web.call([])
assert conn.state == :sent
assert conn.status == 200
end
接收此代码的代码是使用常见的Plug.Parsers解码Json的普通插件:
defmodule MrsNorris.Web do
import Plug.Conn
use Plug.Builder
plug Plug.Parsers, parsers: [:json], pass: ["*/*"], json_decoder: Jason
def init(options), do: options
def call(conn, _opts) do
conn
|> super([])
|> put_resp_content_type("text/plain")
|> send_resp(200, "Welcome Github!\n")
end
end
身体完全是空的(删除了一些不相关的数据):
%Plug.Conn{
adapter: {Plug.Adapters.Test.Conn, :...},
assigns: %{},
body_params: %{},
cookies: %Plug.Conn.Unfetched{aspect: :cookies},
host: "www.example.com",
method: "POST",
owner: #PID<0.306.0>,
params: %{},
path_params: %{},
port: 80,
query_params: %{},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
req_headers: [],
request_path: "/",
resp_cookies: %{},
resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}],
scheme: :http,
}
我做错了什么?