feat(heartbeat): emit heartbeat event to SQLite

This commit is contained in:
2026-07-10 12:11:18 +08:00
parent 0cf57bfaca
commit 2f4783f1f9
3 changed files with 34 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
from fastapi.testclient import TestClient
from app.main import app
from app.models.event import EventType
from app.repositories.event_store import event_store
client = TestClient(app)
@@ -64,6 +66,18 @@ def test_heartbeat_and_monitor():
assert any(c["account_id"] == "bot-003" and c["risk_level"] == 10 for c in clients)
def test_heartbeat_creates_event():
event_store.cleanup(0)
client.post("/v1/heartbeat", json={
"account_id": "bot-heartbeat",
"tenant_code": "rescue",
"risk_level": 10,
"sent_count_today": 5,
})
pending = event_store.fetch_pending(limit=10)
assert any(e.event_type == EventType.HEARTBEAT and e.tenant_code == "rescue" for e in pending)
def test_monitor_page():
r = client.get("/monitor")
assert r.status_code == 200