Where is get/2 statement is documented

Hi all
I am reading the phoenix book now chapter Unit-Testing Plugs and encounter the function get/2. The whole test code

test "login puts the user in the session", %{conn: conn} do
    login_conn = conn
                 |> Auth.login(%Rumbl.User{id: 123})
                 |> send_resp(:ok, "")

    next_conn = get(login_conn, "/")

    assert get_session(next_conn, :user_id) == 123
  end

I could not find the get/2 function on the hexdocs. Could please someone help me?
Thanks

3 Likes

It’s a macro in Phoenix.ConnTest https://hexdocs.pm/phoenix/Phoenix.ConnTest.html#get/3

4 Likes

So when I would call

get(conn, "/")

The request would go through pipeline too?

1 Like

Correct.

2 Likes

and what about the bypass_through. I do not understand how it works.
For example:

setup %{conn: conn} do
    conn = conn
           |> bypass_through(Rumbl.Router, :browser)
           |> get("/")

    {:ok, %{conn: conn}}
  end

And an example test:

test "login puts the user in the session", %{conn: conn} do
    login_conn = conn
                 |> Auth.login(%Rumbl.User{id: 123})
                 |> send_resp(:ok, "")

    next_conn = get(login_conn, "/")

    assert get_session(next_conn, :user_id) == 123
  end

What does the bypass_through in the setup macro? The whole macro I do not understand. Please explain it to me?
How can I understand how router dispatch works?

1 Like

https://hexdocs.pm/phoenix/Phoenix.ConnTest.html#bypass_through/1

It is for when you are testing something like (as per the docs) an authentication plug, but you need to run certain router plugs to set it up for it to work at all.

2 Likes

So as I understood, the controller is not going to call when I bypass_through function call right?

Correct, it is primarily for testing plugs, if you are not testing plugs then you probably do not need it. :slight_smile:

1 Like

@OvermindDL1 thanks so much. Now I got it :wink: