modifications to fix basic tests

This commit is contained in:
Adam Piontek 2021-04-10 12:25:03 -04:00
parent 29e31a05a1
commit aff6c87a1b
10 changed files with 27 additions and 31 deletions

View file

@ -1,10 +1,8 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-11 col-sm-8 col-md-6 col-lg-5 col-xl-4 col-xxl-3"> <div class="col-11 col-sm-8 col-md-6 col-lg-5 col-xl-4 col-xxl-3">
<h2> <h2><%= icon_div @socket, "bi-person-plus", [class: "icon baseline"] %>
<%= icon_div @socket, "bi-person-plus", [class: "icon baseline"] %> Register</h2>
Register
</h2>
<p class="lead">Registration gains additional features, like remembering your song request history.</p> <p class="lead">Registration gains additional features, like remembering your song request history.</p>
<%= form_for @changeset, "#", [phx_change: :validate, phx_submit: :save, novalidate: true, id: "reg_form"], fn f -> %> <%= form_for @changeset, "#", [phx_change: :validate, phx_submit: :save, novalidate: true, id: "reg_form"], fn f -> %>

View file

@ -1,10 +1,8 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-11"> <div class="col-11">
<h2 class="mb-3"> <h2 class="mb-3"><%= icon_div @socket, "bi-sliders", [class: "icon baseline"] %>
<%= icon_div @socket, "bi-sliders", [class: "icon baseline"] %> User Settings</h2>
User Settings
</h2>
<div class="row justify-content-center justify-content-md-start"> <div class="row justify-content-center justify-content-md-start">
<%= live_component @socket, Bones73kWeb.UserLive.Settings.Email, id: "email-#{@current_user.id}", current_user: @current_user %> <%= live_component @socket, Bones73kWeb.UserLive.Settings.Email, id: "email-#{@current_user.id}", current_user: @current_user %>

View file

@ -1,10 +1,8 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-11 col-sm-8 col-md-6 col-lg-5 col-xl-4 col-xxl-3"> <div class="col-11 col-sm-8 col-md-6 col-lg-5 col-xl-4 col-xxl-3">
<h2> <h2><%= icon_div @conn, "bi-door-open", [class: "icon baseline"] %>
<%= icon_div @conn, "bi-door-open", [class: "icon baseline"] %> Log in</h2>
Log in
</h2>
<p class="lead">Who goes there?</p> <p class="lead">Who goes there?</p>
<%= form_for @conn, Routes.user_session_path(@conn, :create), [as: :user, class: "needs-validation", novalidate: true], fn f -> %> <%= form_for @conn, Routes.user_session_path(@conn, :create), [as: :user, class: "needs-validation", novalidate: true], fn f -> %>

View file

@ -279,15 +279,15 @@ defmodule Bones73k.AccountsTest do
end end
test "updates the password", %{user: user} do test "updates the password", %{user: user} do
attrs = %{"current_password" => valid_user_password(), "password" => "new valid password"} attrs = %{"current_password" => valid_user_password(), "password" => "NewValidP420"}
{:ok, user} = Accounts.update_user_password(user, attrs) {:ok, user} = Accounts.update_user_password(user, attrs)
assert is_nil(user.password) assert is_nil(user.password)
assert Accounts.get_user_by_email_and_password(user.email, "new valid password") assert Accounts.get_user_by_email_and_password(user.email, "NewValidP420")
end end
test "deletes all tokens for the given user", %{user: user} do test "deletes all tokens for the given user", %{user: user} do
_ = Accounts.generate_user_session_token(user) _ = Accounts.generate_user_session_token(user)
attrs = %{"current_password" => valid_user_password(), "password" => "new valid password"} attrs = %{"current_password" => valid_user_password(), "password" => "NewValidP420"}
{:ok, _} = Accounts.update_user_password(user, attrs) {:ok, _} = Accounts.update_user_password(user, attrs)
refute Repo.get_by(UserToken, user_id: user.id) refute Repo.get_by(UserToken, user_id: user.id)
end end
@ -470,14 +470,14 @@ defmodule Bones73k.AccountsTest do
end end
test "updates the password", %{user: user} do test "updates the password", %{user: user} do
{:ok, updated_user} = Accounts.reset_user_password(user, %{password: "new valid password"}) {:ok, updated_user} = Accounts.reset_user_password(user, %{password: "NewValidP420"})
assert is_nil(updated_user.password) assert is_nil(updated_user.password)
assert Accounts.get_user_by_email_and_password(user.email, "new valid password") assert Accounts.get_user_by_email_and_password(user.email, "NewValidP420")
end end
test "deletes all tokens for the given user", %{user: user} do test "deletes all tokens for the given user", %{user: user} do
_ = Accounts.generate_user_session_token(user) _ = Accounts.generate_user_session_token(user)
{:ok, _} = Accounts.reset_user_password(user, %{password: "new valid password"}) {:ok, _} = Accounts.reset_user_password(user, %{password: "NewValidP420"})
refute Repo.get_by(UserToken, user_id: user.id) refute Repo.get_by(UserToken, user_id: user.id)
end end
end end

View file

@ -7,9 +7,10 @@ defmodule Bones73kWeb.UserRegistrationControllerTest do
test "renders registration page", %{conn: conn} do test "renders registration page", %{conn: conn} do
conn = get(conn, Routes.user_registration_path(conn, :new)) conn = get(conn, Routes.user_registration_path(conn, :new))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "Register\n </h2>" assert response =~ "Register</h2>"
assert response =~ "Log in\n</a>" assert response =~ "Register</button>"
assert response =~ "Register\n</a>" assert response =~ "Log in</a>"
assert response =~ "Forgot your password?</a>"
end end
test "redirects if already logged in", %{conn: conn} do test "redirects if already logged in", %{conn: conn} do

View file

@ -11,9 +11,10 @@ defmodule Bones73kWeb.UserSessionControllerTest do
test "renders log in page", %{conn: conn} do test "renders log in page", %{conn: conn} do
conn = get(conn, Routes.user_session_path(conn, :new)) conn = get(conn, Routes.user_session_path(conn, :new))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "\n Log in\n </h2>" assert response =~ "Log in</h2>"
assert response =~ "Register\n</a>" assert response =~ "Log in</button>"
assert response =~ "Log in\n</a>" assert response =~ "Register</a>"
assert response =~ "Forgot your password?</a>"
end end
test "redirects if already logged in", %{conn: conn, user: user} do test "redirects if already logged in", %{conn: conn, user: user} do
@ -61,7 +62,7 @@ defmodule Bones73kWeb.UserSessionControllerTest do
}) })
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "\n Log in\n </h2>" assert response =~ "Log in</h2>"
assert response =~ "Invalid email or password" assert response =~ "Invalid email or password"
end end
end end
@ -108,7 +109,7 @@ defmodule Bones73kWeb.UserSessionControllerTest do
}) })
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "\n Log in\n </h2>" assert response =~ "Log in</h2>"
assert response =~ "Invalid email or password" assert response =~ "Invalid email or password"
end end
end end

View file

@ -10,7 +10,7 @@ defmodule Bones73kWeb.UserSettingsControllerTest do
test "renders settings page", %{conn: conn} do test "renders settings page", %{conn: conn} do
conn = get(conn, Routes.user_settings_path(conn, :edit)) conn = get(conn, Routes.user_settings_path(conn, :edit))
response = html_response(conn, 200) response = html_response(conn, 200)
assert response =~ "User Settings\n</h2>" assert response =~ "User Settings</h2>"
end end
test "redirects if user is not logged in" do test "redirects if user is not logged in" do

View file

@ -17,7 +17,7 @@ defmodule Bones73kWeb.UserLive.RegistrationTest do
test "displays registration form", %{conn: conn} do test "displays registration form", %{conn: conn} do
{:ok, _view, html} = live_isolated(conn, Bones73kWeb.UserLive.Registration) {:ok, _view, html} = live_isolated(conn, Bones73kWeb.UserLive.Registration)
assert html =~ "Register\n </h2>" assert html =~ "Register</h2>"
assert html =~ "Email</label>" assert html =~ "Email</label>"
end end
@ -29,7 +29,7 @@ defmodule Bones73kWeb.UserLive.RegistrationTest do
|> form("#reg_form", %{"user" => %{"email" => "abc", "password" => "abc"}}) |> form("#reg_form", %{"user" => %{"email" => "abc", "password" => "abc"}})
|> render_change() |> render_change()
assert html =~ "Register\n </h2>" assert html =~ "Register</h2>"
assert html =~ "must be a valid email address" assert html =~ "must be a valid email address"
assert html =~ "should be at least #{User.min_password()} character(s)" assert html =~ "should be at least #{User.min_password()} character(s)"
assert html =~ "type=\"submit\" disabled=\"disabled\"" assert html =~ "type=\"submit\" disabled=\"disabled\""

View file

@ -39,7 +39,7 @@ defmodule Bones73kWeb.UserLive.ResetPasswordTest do
{:ok, view, _html} = live_isolated(conn, Bones73kWeb.UserLive.ResetPassword) {:ok, view, _html} = live_isolated(conn, Bones73kWeb.UserLive.ResetPassword)
# Render submitting a new password # Render submitting a new password
new_pw = "valid_new_pass_123" new_pw = "Valid_new_pass_123"
form_data = %{"user" => %{"password" => new_pw, "password_confirmation" => new_pw}} form_data = %{"user" => %{"password" => new_pw, "password_confirmation" => new_pw}}
_html = form(view, "#pw_reset_form", form_data) |> render_submit() _html = form(view, "#pw_reset_form", form_data) |> render_submit()

View file

@ -5,7 +5,7 @@ defmodule Bones73k.AccountsFixtures do
""" """
def unique_user_email, do: "user#{System.unique_integer()}@example.com" def unique_user_email, do: "user#{System.unique_integer()}@example.com"
def valid_user_password, do: "hello world!" def valid_user_password, do: "ValidPass47"
def user_fixture(attrs \\ %{}) do def user_fixture(attrs \\ %{}) do
{:ok, user} = {:ok, user} =