49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from pytest import MonkeyPatch
|
|
|
|
import k1link.web.app as web_app
|
|
|
|
|
|
def test_ble_scan_exposes_every_device_and_only_labels_likely_k1(
|
|
monkeypatch: MonkeyPatch,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
async def fake_scan(duration_seconds: float) -> dict[str, Any]:
|
|
assert duration_seconds == 6.0
|
|
return {
|
|
"devices": [
|
|
{
|
|
"macos_uuid": "K1-UUID",
|
|
"name": "XGR-A46BE7",
|
|
"local_name": "XGR-A46BE7",
|
|
"rssi": -51,
|
|
"k1_name_candidate": True,
|
|
},
|
|
{
|
|
"macos_uuid": "OTHER-UUID",
|
|
"name": "AirPods Pro",
|
|
"local_name": "AirPods Pro",
|
|
"rssi": -62,
|
|
"k1_name_candidate": False,
|
|
},
|
|
]
|
|
}
|
|
|
|
monkeypatch.setattr(web_app, "scan", fake_scan)
|
|
service = web_app.ConsoleService(tmp_path)
|
|
|
|
state = asyncio.run(service.scan_ble(6.0))
|
|
|
|
assert state["selected_device_id"] is None
|
|
assert [device["device_id"] for device in state["devices"]] == [
|
|
"K1-UUID",
|
|
"OTHER-UUID",
|
|
]
|
|
assert [device["likely_k1"] for device in state["devices"]] == [True, False]
|
|
|