user settings updated to lv and lv tests created. all tests working
This commit is contained in:
parent
24502e2667
commit
ef7b8e0bb8
26 changed files with 389 additions and 288 deletions
|
@ -13,7 +13,8 @@ defmodule Bones73kWeb.UserRegistrationControllerTest do
|
|||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
conn = conn |> log_in_user(user_fixture()) |> get(Routes.user_registration_path(conn, :new))
|
||||
to = Routes.user_registration_path(conn, :new)
|
||||
conn = conn |> log_in_user(user_fixture()) |> get(to)
|
||||
assert redirected_to(conn) == "/"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,12 @@ defmodule Bones73kWeb.UserResetPasswordControllerTest do
|
|||
response = html_response(conn, 200)
|
||||
assert response =~ "Forgot your password?\n </h3>"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
to = Routes.user_reset_password_path(conn, :new)
|
||||
conn = conn |> log_in_user(user_fixture()) |> get(to)
|
||||
assert redirected_to(conn) == "/"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/reset_password" do
|
||||
|
|
|
@ -10,7 +10,7 @@ defmodule Bones73kWeb.UserSettingsControllerTest do
|
|||
test "renders settings page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :edit))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ "User Settings\n</h3>"
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in" do
|
||||
|
@ -20,71 +20,6 @@ defmodule Bones73kWeb.UserSettingsControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "PUT /users/settings/update_password" do
|
||||
test "updates the user password and resets tokens", %{conn: conn, user: user} do
|
||||
new_password_conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update_password), %{
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
|
||||
assert get_flash(new_password_conn, :info) =~ "Password updated successfully"
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
end
|
||||
|
||||
test "does not update password on invalid data", %{conn: conn} do
|
||||
old_password_conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update_password), %{
|
||||
"current_password" => "invalid",
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(old_password_conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
assert response =~ "is not valid"
|
||||
|
||||
assert get_session(old_password_conn, :user_token) == get_session(conn, :user_token)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /users/settings/update_email" do
|
||||
@tag :capture_log
|
||||
test "updates the user email", %{conn: conn, user: user} do
|
||||
conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update_email), %{
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{"email" => unique_user_email()}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :info) =~ "A link to confirm your email"
|
||||
assert Accounts.get_user_by_email(user.email)
|
||||
end
|
||||
|
||||
test "does not update email on invalid data", %{conn: conn} do
|
||||
conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update_email), %{
|
||||
"current_password" => "invalid",
|
||||
"user" => %{"email" => "with spaces"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "is not valid"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /users/settings/confirm_email/:token" do
|
||||
setup %{user: user} do
|
||||
email = unique_user_email()
|
||||
|
|
|
@ -52,9 +52,6 @@ defmodule Bones73kWeb.AdminDashboardLiveTest do
|
|||
assert "/" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert "/users/log_in" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert html_response(conn, 200) =~
|
||||
"You were logged out. Please login again to continue using our application."
|
||||
end
|
||||
|
|
|
@ -4,12 +4,6 @@ defmodule Bones73kWeb.PageLiveTest do
|
|||
import Phoenix.LiveViewTest
|
||||
import Bones73k.AccountsFixtures
|
||||
|
||||
test "disconnected and connected render without authentication should redirect to login page",
|
||||
%{conn: conn} do
|
||||
# If we don't previously log in we will be redirected to the login page
|
||||
assert {:error, {:redirect, %{to: "/users/log_in"}}} = live(conn, "/")
|
||||
end
|
||||
|
||||
test "disconnected and connected render with authentication should redirect to index page", %{
|
||||
conn: conn
|
||||
} do
|
||||
|
@ -44,9 +38,6 @@ defmodule Bones73kWeb.PageLiveTest do
|
|||
assert "/" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert "/users/log_in" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert html_response(conn, 200) =~
|
||||
"You were logged out. Please login again to continue using our application."
|
||||
end
|
||||
|
|
|
@ -188,16 +188,13 @@ defmodule Bones73kWeb.PropertyLiveTest do
|
|||
assert_receive {:DOWN, ^ref, _, _, _}
|
||||
refute Process.alive?(index_live.pid)
|
||||
|
||||
# Assert our liveview was redirected, following first to /users/force_logout, then to "/", and then to "/users/log_in"
|
||||
# Assert our liveview was redirected, following first to /users/force_logout, then to "/"
|
||||
assert_redirect(index_live, "/users/force_logout")
|
||||
|
||||
conn = get(conn, "/users/force_logout")
|
||||
assert "/" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert "/users/log_in" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert html_response(conn, 200) =~
|
||||
"You were logged out. Please login again to continue using our application."
|
||||
end
|
||||
|
@ -338,9 +335,6 @@ defmodule Bones73kWeb.PropertyLiveTest do
|
|||
assert "/" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert "/users/log_in" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert html_response(conn, 200) =~
|
||||
"You were logged out. Please login again to continue using our application."
|
||||
end
|
||||
|
|
|
@ -6,8 +6,7 @@ defmodule Bones73kWeb.UserLive.ResetPasswordTest do
|
|||
|
||||
alias Bones73k.Repo
|
||||
alias Bones73k.Accounts
|
||||
alias Bones73k.Accounts.User
|
||||
alias Bones73k.Accounts.UserToken
|
||||
alias Bones73k.Accounts.{User, UserToken}
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = user_fixture()
|
||||
|
@ -46,7 +45,7 @@ defmodule Bones73kWeb.UserLive.ResetPasswordTest do
|
|||
|
||||
# Confirm redirected
|
||||
flash = assert_redirected(view, Routes.user_session_path(conn, :new))
|
||||
assert flash["success"] == "Password reset successfully."
|
||||
assert flash["info"] == "Password reset successfully."
|
||||
|
||||
# Confirm password was updated
|
||||
assert Accounts.get_user_by_email_and_password(user.email, new_pw)
|
||||
|
|
|
@ -54,9 +54,6 @@ defmodule Bones73kWeb.UserDashboardLiveTest do
|
|||
assert "/" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert "/users/log_in" = redir_path = redirected_to(conn, 302)
|
||||
conn = get(recycle(conn), redir_path)
|
||||
|
||||
assert html_response(conn, 200) =~
|
||||
"You were logged out. Please login again to continue using our application."
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue