Repository: home-assistant/core
File: tests/components/vesync/test_config_flow.py (Python)

Code before:
    assert result["type"] is FlowResultType.FORM

    with patch(
        "pyvesync.vesync.VeSync.login",
        side_effect=VeSyncLoginError("Mock login failed"),
    ):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            {CONF_USERNAME: "user", CONF_PASSWORD: "pass"},
        )

    assert result["type"] is FlowResultType.FORM
    assert result["errors"] == {"base": "invalid_auth"}


async def test_config_flow_user_input(hass: HomeAssistant) -> None:
    """Test config flow with user input."""
    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": "user"}
    )
    assert result["type"] is FlowResultType.FORM

    with patch("pyvesync.vesync.VeSync.login"):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            {CONF_USERNAME: "user", CONF_PASSWORD: "pass"},
        )

    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert result["data"][CONF_USERNAME] == "user"
    assert result["data"][CONF_PASSWORD] == "pass"


async def test_reauth_flow(hass: HomeAssistant) -> None:
    """Test a successful reauth flow."""
    mock_entry = MockConfigEntry(
        domain=DOMAIN,
        unique_id="account_id",
    )
    mock_entry.add_to_hass(hass)

    result = await mock_entry.start_reauth_flow(hass)

    assert result["step_id"] == "reauth_confirm"
    assert result["type"] is FlowResultType.FORM
    with (
        patch("pyvesync.vesync.VeSync") as mock_vesync,
        patch(
            "pyvesync.auth.VeSyncAuth._account_id", new_callable=PropertyMock
        ) as mock_account_id,
    ):

Review comment (suggestion):
Also assert the unique id
```py
assert result["result"].unique_id == "..."
```

Code after:
    ):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            {CONF_USERNAME: "user", CONF_PASSWORD: "pass"},
        )

    assert result["type"] is FlowResultType.FORM
    assert result["errors"] == {"base": "invalid_auth"}


async def test_config_flow_user_input(hass: HomeAssistant) -> None:
    """Test config flow with user input."""
    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": "user"}
    )
    assert result["type"] is FlowResultType.FORM

    with patch("pyvesync.vesync.VeSync.login"):
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            {CONF_USERNAME: "user", CONF_PASSWORD: "pass"},
        )

    assert result["type"] is FlowResultType.CREATE_ENTRY
    assert result["data"][CONF_USERNAME] == "user"
    assert result["data"][CONF_PASSWORD] == "pass"
    assert result["result"].unique_id == "TESTACCOUNTID"


async def test_reauth_flow(hass: HomeAssistant) -> None:
    """Test a successful reauth flow."""
    mock_entry = MockConfigEntry(
        domain=DOMAIN,
        unique_id="account_id",
    )
    mock_entry.add_to_hass(hass)

    result = await mock_entry.start_reauth_flow(hass)

    assert result["step_id"] == "reauth_confirm"
    assert result["type"] is FlowResultType.FORM
    with (
        patch("pyvesync.vesync.VeSync") as mock_vesync,
        patch(
            "pyvesync.auth.VeSyncAuth._account_id", new_callable=PropertyMock
        ) as mock_account_id,
    ):
        instance = mock_vesync.return_value
        instance.login.return_value = None
        mock_account_id.return_value = "account_id"
        result = await hass.config_entries.flow.async_configure(