feat(event): add SQLite outbound event store
This commit is contained in:
42
channel-service/tests/test_event_store.py
Normal file
42
channel-service/tests/test_event_store.py
Normal 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
|
||||
Reference in New Issue
Block a user