Reputation: 913
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
Upvotes: 5
Views: 630