how to login a user using Wallaby without going through the regular login process? (Setting cookies/sessions)

534 Views Asked by At

I would like to know how to login a user in the session without creating work around routes in the test enviornment or logging the user in through the standard user flow. Is there a way to set the cookie/session so that there is a current_user?

Here is some discussion about it: https://github.com/elixir-wallaby/wallaby/issues/57

Since cookies can be read and set via Wallaby I'm wondering how one would use those to setup the current_user and bypass a manual login flow.

ideally i'd want something like:

test "visit dashboard", %{session: session} do
  {:ok, user} =
      MyApp.Accounts.create_user(%{email: "[email protected]", password: "123456"})

  session = Wallaby.Browser.set_cookie(session, :current_user, user)

  # start test of protected page
  Wallaby.Browser.visit(session, "/dashboard")

  # etc.
  ...

end
0

There are 0 best solutions below