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.

62 lines
1.7 KiB
Python

from __future__ import annotations
from types import SimpleNamespace
from fastapi import Response
import app.a2a.router as a2a_module
from app.a2a.models import A2ARpcRequest
from app.core.models import CoreBusySlot
class _DummyCoreService:
def check_availability(
self,
start: str,
end: str,
calendar_ids: list[str] | None,
) -> SimpleNamespace:
checked = calendar_ids or ["primary"]
busy_slots = [CoreBusySlot(calendar_id=checked[0], start=start, end=end)]
return SimpleNamespace(
start=start,
end=end,
available=False,
busy_slots=busy_slots,
checked_calendars=checked,
)
class _AllowAuthBackend:
def authenticate(
self,
*,
x_api_key: str | None,
authorization: str | None,
required_scopes: set[str],
) -> None:
return None
def test_a2a_send_message_returns_availability(monkeypatch) -> None:
monkeypatch.setattr(a2a_module, "core_service", _DummyCoreService())
monkeypatch.setattr(a2a_module, "auth_backend", _AllowAuthBackend())
request = A2ARpcRequest(
jsonrpc="2.0",
id="req-1",
method="SendMessage",
params={
"start": "2026-03-10T09:00:00+01:00",
"end": "2026-03-10T10:00:00+01:00",
"calendar_ids": ["primary"],
},
)
response = a2a_module.a2a_rpc(request, Response())
assert response.error is None
assert response.result is not None
assert response.result["type"] == "availability.result"
assert response.result["availability"]["available"] is False
assert response.result["availability"]["checked_calendars"] == ["primary"]