diff --git a/test/towerops_web/live/user_settings_live_test.exs b/test/towerops_web/live/user_settings_live_test.exs index ee9ac34b..c4cabde0 100644 --- a/test/towerops_web/live/user_settings_live_test.exs +++ b/test/towerops_web/live/user_settings_live_test.exs @@ -284,5 +284,52 @@ defmodule ToweropsWeb.UserSettingsLiveTest do html = render_click(view, "check_password_breach", %{}) assert html =~ "Account Settings" end + + test "check_password_breach with a value drives the HIBP path", %{conn: conn} do + {:ok, view, _html} = live(conn, ~p"/users/settings?tab=account") + + # Submit a password to the breach check. We don't care whether the + # response is :ok / count / :unknown — the handler should not crash. + html = view |> element("#new-password") |> render_blur(%{"value" => "Sup3rS3cretP@ssw0rd1!"}) + assert html =~ "Account Settings" + end + end + + describe "UserSettingsLive update_email error path" do + setup :register_and_log_in_user_with_sudo + + test "update_email with invalid params keeps the form on the page", %{conn: conn} do + {:ok, view, _html} = live(conn, ~p"/users/settings?tab=account") + + # Submit invalid (empty) email + missing current password — Accounts.change_user_email + # produces an invalid changeset and the handler should re-render the form. + html = + render_change(view, "update_email", %{ + "user" => %{"email" => "", "current_password" => ""} + }) + + assert html =~ "Account Settings" + end + end + + describe "UserSettingsLive update_password error path" do + setup :register_and_log_in_user_with_sudo + + test "update_password with mismatched confirmation re-renders the form", %{conn: conn} do + {:ok, view, _html} = live(conn, ~p"/users/settings?tab=account") + + html = + render_submit(view, "update_password", %{ + "user" => %{ + "password" => "newpassword123", + "password_confirmation" => "different123", + "current_password" => "wrong" + } + }) + + # The re-render leaves us on the same tab; the changeset error appears + # inline. Either flash or form helper text contains "Account Settings". + assert html =~ "Account Settings" + end end end