from unittest.mock import MagicMock, patch

import pytest

from planemapper.provisioning import ProvisioningError
from planemapper.provisioning.wifi import join_home_wifi


def test_join_home_wifi_success() -> None:
    mock_result = MagicMock()
    mock_result.returncode = 0
    with patch("planemapper.provisioning.wifi.subprocess.run", return_value=mock_result):
        join_home_wifi("MySSID", "MyPass")


def test_join_home_wifi_failure() -> None:
    mock_result = MagicMock()
    mock_result.returncode = 1
    mock_result.stderr = b"Error: connection failed"
    with patch("planemapper.provisioning.wifi.subprocess.run", return_value=mock_result):
        with pytest.raises(ProvisioningError, match="nmcli failed"):
            join_home_wifi("MySSID", "wrongpassword")
