Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
defmodule Stackfooter.ConsoleControllerTest do | ||
use Stackfooter.ConnCase | ||
alias Stackfooter.UserAuth | ||
|
||
@apikey "4cy7uf63Lw2Sx6652YmLwBKy662weU4q" | ||
|
||
@session Plug.Session.init( | ||
store: :cookie, | ||
key: "_app", | ||
encryption_salt: "yadayada", | ||
signing_salt: "yadayada" | ||
) | ||
|
||
setup config do | ||
reset_api_keys() | ||
|
||
if username = config[:login_as] do | ||
user = insert_user(username: username, api_keys: [@apikey]) | ||
conn = assign(build_conn(), :current_user, user) | ||
cond do | ||
config[:no_login] -> | ||
{:ok, conn: build_conn()} | ||
%{username: username, password: password} = config[:login_as] -> | ||
user = insert_user(username: username, api_keys: [@apikey], password: password) | ||
|
||
conn = Plug.Session.call(build_conn(), @session) |> fetch_session() | ||
{:ok, conn} = UserAuth.login_by_username_and_pass(conn, username, password, repo: Repo) | ||
|
||
{:ok, conn: conn, user: user} | ||
else | ||
{:ok, conn: build_conn()} | ||
{:ok, conn: conn, user: user} | ||
true -> | ||
{:ok, conn: build_conn()} | ||
end | ||
end | ||
|
||
@tag login_as: "rjsamson1234" | ||
test "Trade path is authenticated", %{conn: conn, user: _user} do | ||
@tag no_login: true | ||
test "Redirects if not authenticated", %{conn: conn} do | ||
conn = get(conn, "/console") | ||
assert html_response(conn, 200) =~ "rjsamson1234" | ||
assert redirected_to(conn) == session_path(conn, :new) | ||
end | ||
|
||
test "Redirects if not authenticated", %{conn: conn} do | ||
@tag login_as: %{username: "rjsamson1234", password: "password"} | ||
test "Trade path is authenticated", %{conn: conn, user: _user} do | ||
conn = get(conn, "/console") | ||
assert redirected_to(conn) == session_path(conn, :new) | ||
assert html_response(conn, 200) =~ "rjsamson1234" | ||
end | ||
end |