defmodule ToweropsWeb.UserResetPasswordLiveTest do
  use ToweropsWeb.ConnCase, async: true

  import Phoenix.LiveViewTest
  import Towerops.AccountsFixtures

  alias Towerops.Accounts

  describe "reset password page" do
    setup do
      user = user_fixture()
      token = extract_user_token(fn url -> Accounts.deliver_user_reset_password_instructions(user, url) end)

      %{user: user, token: token}
    end

    test "renders reset password page with valid token", %{conn: conn, token: token} do
      {:ok, _lv, html} = live(conn, ~p"/users/reset-password/#{token}")

      assert html =~ "Reset password"
      assert html =~ "Enter your new password below"
    end

    test "redirects with invalid token", %{conn: conn} do
      {:error, {:redirect, %{to: to, flash: flash}}} = live(conn, ~p"/users/reset-password/invalid-token")

      assert to == ~p"/users/log-in"
      assert flash["error"] == "Reset password link is invalid or has expired."
    end
  end

  # NOTE: Password breach checking tests are placeholders
  # Full implementation requires Req mocking setup with Mox
  # These tests verify the LiveView renders correctly
  # Real HIBP integration would be tested in integration tests
end
