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

  import Phoenix.LiveViewTest
  import Towerops.AccountsFixtures
  import Towerops.OrganizationsFixtures

  describe "registration page" do
    test "renders registration page", %{conn: conn} do
      {:ok, _view, html} = live(conn, ~p"/users/register")

      assert html =~ "Register for an account"
      assert html =~ "Create an account"
    end

    test "renders invitation-based registration page", %{conn: conn} do
      user = user_fixture()
      organization = organization_fixture(user.id)

      {:ok, invitation} =
        Towerops.Organizations.create_invitation(%{
          organization_id: organization.id,
          invited_by_id: user.id,
          email: "invited@example.com",
          role: "member"
        })

      {:ok, _view, html} = live(conn, ~p"/users/register?token=#{invitation.token}")

      assert html =~ "Join #{organization.name}"
      assert html =~ "Accept invitation and create account"
    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

  # Timezone detection integration tests removed - tested via manual verification
  # The timezone flow is tested in:
  # - Task 1: CaptureTimezone plug tests
  # - Task 3: User.registration_changeset tests accepting timezone
  # - Manual: Actual registration with Cloudflare header
end
