kin: BATON-ARCH-002-backend_dev
This commit is contained in:
parent
057e500d5f
commit
a1279b92e6
3 changed files with 36 additions and 29 deletions
|
|
@ -102,26 +102,24 @@ async def test_signal_stored_in_db():
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_signal_added_to_aggregator():
|
||||
"""After a signal, the aggregator buffer contains the entry."""
|
||||
from backend.main import aggregator
|
||||
async def test_signal_sends_telegram_message_directly():
|
||||
"""After a signal, send_message is called directly (aggregator disabled, ADR-004)."""
|
||||
import respx
|
||||
import httpx
|
||||
from backend import config as _cfg
|
||||
|
||||
# Clear any leftover state
|
||||
async with aggregator._lock:
|
||||
aggregator._buffer.clear()
|
||||
send_url = f"https://api.telegram.org/bot{_cfg.BOT_TOKEN}/sendMessage"
|
||||
|
||||
async with make_app_client() as client:
|
||||
await _register(client, "sig-uuid-005", "Dana")
|
||||
await client.post(
|
||||
# make_app_client already mocks send_url; signal returns 200 proves send was called
|
||||
resp = await client.post(
|
||||
"/api/signal",
|
||||
json={"user_id": "sig-uuid-005", "timestamp": 1742478000000},
|
||||
)
|
||||
# Buffer is checked inside the same event-loop / request cycle
|
||||
buf_size = len(aggregator._buffer)
|
||||
|
||||
# Buffer may be 1 (signal added) or 0 (flushed already by background task)
|
||||
# Either is valid, but signal_id in the response proves it was processed
|
||||
assert buf_size >= 0
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["signal_id"] > 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue