You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import app.core.service as core_module
|
|
from app.config import get_settings
|
|
from app.core.service import CoreAgentService
|
|
|
|
|
|
class _FakeFreeBusy:
|
|
def __init__(self, payload: dict[str, object]) -> None:
|
|
self.payload = payload
|
|
self.last_query_body: dict[str, object] | None = None
|
|
|
|
def query(self, body: dict[str, object]) -> _FakeFreeBusy:
|
|
self.last_query_body = body
|
|
return self
|
|
|
|
def execute(self) -> dict[str, object]:
|
|
return self.payload
|
|
|
|
|
|
class _FakeCalendarService:
|
|
def __init__(self, payload: dict[str, object]) -> None:
|
|
self._freebusy = _FakeFreeBusy(payload)
|
|
|
|
def freebusy(self) -> _FakeFreeBusy:
|
|
return self._freebusy
|
|
|
|
|
|
def test_core_availability_maps_busy_slots(monkeypatch) -> None:
|
|
payload = {
|
|
"calendars": {
|
|
"primary": {
|
|
"busy": [
|
|
{
|
|
"start": "2026-03-10T09:00:00+01:00",
|
|
"end": "2026-03-10T10:00:00+01:00",
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
fake_service = _FakeCalendarService(payload)
|
|
monkeypatch.setattr(core_module, "build_calendar_service", lambda _: fake_service)
|
|
|
|
service = CoreAgentService(settings=get_settings())
|
|
result = service.check_availability(
|
|
start="2026-03-10T09:00:00+01:00",
|
|
end="2026-03-10T10:00:00+01:00",
|
|
calendar_ids=["primary"],
|
|
)
|
|
|
|
assert result.available is False
|
|
assert result.checked_calendars == ["primary"]
|
|
assert len(result.busy_slots) == 1
|
|
assert result.busy_slots[0].calendar_id == "primary"
|
|
assert result.busy_slots[0].start == "2026-03-10T09:00:00+01:00"
|
|
assert result.busy_slots[0].end == "2026-03-10T10:00:00+01:00"
|