lundi 24 septembre 2018

Using response data in a controller test

I have the following test in which I use data from a previous request:

test "renders user when data is valid", %{conn: conn} do
  conn = post conn, user_path(conn, :create), user: @create_attrs
  assert %{"jwt" => jwt} = json_response(conn, 201)["data"]

  conn = get (conn |> put_req_header("Authorization", "Bearer #{jwt}")), user_path(conn, :show)

  assert %{"id" => _, "email" => "some email", "password_hash" => "some password_hash"} = json_response(conn, 201)["data"]

end

However this test fails with:

** (Plug.Conn.AlreadySentError) the response was already sent

How can I reuse the conn here?

Aucun commentaire:

Enregistrer un commentaire