Integration test with POST verb

Hi all

I have signin route defined as follow:

post “/signin”, SessionController, :signin

the controller

  def signin(conn, %{"login" => %{"username" => username, "password" => password }}) do

   case Server.sign_in(%UserLogin{username: username, password: password}) do
      {:ok, user = %UserInfo{}} ->
        conn
        |> put_session(:sid, Jwt.encrypt(user))
        |> redirect(to: session_path(conn, :welcome))

      {:error, _} ->
        conn
        |> put_layout(false)
        |> render("index.html")
   end
  end

I am trying to write an integration test for the signin method and it does not work es expected.

The integration test code:

  test "POST /signin", %{conn: conn, bypass: bypass, user: user} do

    Bypass.expect bypass, fn conn ->
      Plug.Conn.resp(conn, 200, user)
    end

    conn = post conn, "/signin"
    assert html_response(conn, 302)

  end

and as output I’ve got:

How can I test HTTP POST request?

Thanks

1 Like

I’ve forgot to pass

conn = post conn, “/signin”, %{“login” => %{“username” => “foo”, “password” => “boo” }}

2 Likes

How come is this an integration test since you bypass the actual call?