feat(event): add SQLite outbound event store

This commit is contained in:
2026-07-10 12:06:19 +08:00
parent b2e5cc187c
commit 41cb52daa1
3 changed files with 173 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import os
import tempfile
import pytest
from app.models.event import EventType, OutboundEvent
from app.repositories.event_store import EventStore
@pytest.fixture
def store():
fd, path = tempfile.mkstemp(suffix=".db")
os.close(fd)
store = EventStore(path)
yield store
os.unlink(path)
def test_save_and_fetch_pending(store):
event = OutboundEvent(
event_type=EventType.HEARTBEAT,
account_id="bot-001",
tenant_code="rescue",
data={"online_status": "online"},
)
store.save(event)
pending = store.fetch_pending(limit=10)
assert len(pending) == 1
assert pending[0].event_id == event.event_id
def test_mark_delivered(store):
event = OutboundEvent(
event_type=EventType.HEARTBEAT,
account_id="bot-001",
tenant_code="rescue",
data={},
)
store.save(event)
store.mark_delivered(event.event_id)
pending = store.fetch_pending(limit=10)
assert len(pending) == 0