after running phx.gen.auth

This commit is contained in:
Thelonius Kort
2020-07-30 15:38:05 +02:00
parent 52ae841f13
commit 77a89e2682
37 changed files with 2469 additions and 1 deletions

View File

@ -40,4 +40,30 @@ defmodule ClipWeb.ConnCase do
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
@doc """
Setup helper that registers and logs in users.
setup :register_and_log_in_user
It stores an updated connection and a registered user in the
test context.
"""
def register_and_log_in_user(%{conn: conn}) do
user = Clip.AccountsFixtures.user_fixture()
%{conn: log_in_user(conn, user), user: user}
end
@doc """
Logs the given `user` into the `conn`.
It returns an updated `conn`.
"""
def log_in_user(conn, user) do
token = Clip.Accounts.generate_user_session_token(user)
conn
|> Phoenix.ConnTest.init_test_session(%{})
|> Plug.Conn.put_session(:user_token, token)
end
end