Packages

Flexible, lightweight and productive authentication for Plug, Phoenix and Ecto projects

Current section

Files

Jump to
entrance priv templates gen phx_modules require_login_test.eex
Raw

priv/templates/gen/phx_modules/require_login_test.eex

defmodule <%= @context[:web_module] %>.<%= @context[:scoped] %>Test do
@moduledoc """
Ajust the tests conform your app configuration :)
"""
@login_route "/session/new"
use <%= @context[:web_module] %>.ConnCase, async: true
alias <%= @context[:web_module] %>.<%= @context[:scoped] %>
setup do
opts =
Plug.Session.init(
store: :cookie,
key: "test_key",
encryption_salt: "test_encryption_salt",
signing_salt: "test_signing_salt",
log: false,
encrypt: false
)
session_conn =
build_conn()
|> Plug.Session.call(opts)
|> fetch_session()
|> fetch_flash()
%{session_conn: session_conn}
end
describe "<%= @context[:web_module] %>.<%= @context[:scoped] %>.call/2" do
@tag :skip
test "when user is not logged in, redirect to login route", %{
session_conn: session_conn
} do
assert @login_route = redirected_to(RequireLogin.call(session_conn, %{}), 302)
end
end
end