72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from adapter.matrix.store import (
|
|
get_room_meta,
|
|
get_room_state,
|
|
get_skills_message_id,
|
|
get_user_meta,
|
|
next_chat_id,
|
|
set_room_meta,
|
|
set_room_state,
|
|
set_skills_message_id,
|
|
set_user_meta,
|
|
)
|
|
from core.store import InMemoryStore
|
|
|
|
|
|
@pytest.fixture
|
|
def store() -> InMemoryStore:
|
|
return InMemoryStore()
|
|
|
|
|
|
async def test_room_meta_roundtrip(store: InMemoryStore):
|
|
meta = {
|
|
"room_type": "chat",
|
|
"chat_id": "C1",
|
|
"display_name": "Чат 1",
|
|
"matrix_user_id": "@alice:m.org",
|
|
}
|
|
await set_room_meta(store, "!r:m.org", meta)
|
|
assert await get_room_meta(store, "!r:m.org") == meta
|
|
|
|
|
|
async def test_room_meta_missing(store: InMemoryStore):
|
|
assert await get_room_meta(store, "!nonexistent:m.org") is None
|
|
|
|
|
|
async def test_user_meta_roundtrip(store: InMemoryStore):
|
|
meta = {
|
|
"platform_user_id": "usr-1",
|
|
"display_name": "Alice",
|
|
"space_id": None,
|
|
"settings_room_id": None,
|
|
"next_chat_index": 1,
|
|
}
|
|
await set_user_meta(store, "@alice:m.org", meta)
|
|
assert await get_user_meta(store, "@alice:m.org") == meta
|
|
|
|
|
|
async def test_room_state_roundtrip(store: InMemoryStore):
|
|
await set_room_state(store, "!r:m.org", "idle")
|
|
assert await get_room_state(store, "!r:m.org") == "idle"
|
|
await set_room_state(store, "!r:m.org", "waiting_response")
|
|
assert await get_room_state(store, "!r:m.org") == "waiting_response"
|
|
|
|
|
|
async def test_room_state_default_idle(store: InMemoryStore):
|
|
assert await get_room_state(store, "!unknown:m.org") == "idle"
|
|
|
|
|
|
async def test_next_chat_id_increments(store: InMemoryStore):
|
|
uid = "@alice:m.org"
|
|
await set_user_meta(store, uid, {"next_chat_index": 1})
|
|
assert await next_chat_id(store, uid) == "C1"
|
|
assert await next_chat_id(store, uid) == "C2"
|
|
assert await next_chat_id(store, uid) == "C3"
|
|
|
|
|
|
async def test_skills_message_roundtrip(store: InMemoryStore):
|
|
await set_skills_message_id(store, "!room", "$event")
|
|
assert await get_skills_message_id(store, "!room") == "$event"
|