test(01-04): add matrix space regression coverage
- add MAT-01..MAT-07 and MAT-09..MAT-12 regression tests for matrix adapter - extend store and dispatcher coverage for pending confirmations and settings dashboard - verify matrix adapter suite and full pytest suite stay green
This commit is contained in:
parent
6f1bdb4077
commit
97a3dc35ea
6 changed files with 382 additions and 0 deletions
78
tests/adapter/matrix/test_invite_space.py
Normal file
78
tests/adapter/matrix/test_invite_space.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from adapter.matrix.bot import build_runtime
|
||||
from adapter.matrix.handlers.auth import handle_invite
|
||||
from adapter.matrix.store import get_room_meta, get_user_meta
|
||||
from sdk.mock import MockPlatformClient
|
||||
|
||||
|
||||
def _make_client():
|
||||
space_resp = SimpleNamespace(room_id="!space:example.org")
|
||||
chat_resp = SimpleNamespace(room_id="!chat1:example.org")
|
||||
return SimpleNamespace(
|
||||
join=AsyncMock(),
|
||||
room_create=AsyncMock(side_effect=[space_resp, chat_resp]),
|
||||
room_put_state=AsyncMock(),
|
||||
room_invite=AsyncMock(),
|
||||
room_send=AsyncMock(),
|
||||
)
|
||||
|
||||
|
||||
async def test_mat01_invite_creates_space_and_chat1():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
client = _make_client()
|
||||
room = SimpleNamespace(room_id="!dm:example.org", display_name="Alice")
|
||||
event = SimpleNamespace(sender="@alice:example.org", membership="invite")
|
||||
|
||||
await handle_invite(client, room, event, runtime.platform, runtime.store, runtime.auth_mgr)
|
||||
|
||||
first_call = client.room_create.call_args_list[0]
|
||||
assert first_call.kwargs.get("space") is True
|
||||
assert client.room_create.await_count == 2
|
||||
|
||||
client.room_put_state.assert_awaited_once()
|
||||
kwargs = client.room_put_state.call_args.kwargs
|
||||
assert kwargs.get("event_type") == "m.space.child"
|
||||
assert kwargs.get("state_key") == "!chat1:example.org"
|
||||
assert kwargs.get("room_id") == "!space:example.org"
|
||||
|
||||
user_meta = await get_user_meta(runtime.store, "@alice:example.org")
|
||||
assert user_meta is not None
|
||||
assert user_meta["space_id"] == "!space:example.org"
|
||||
|
||||
room_meta = await get_room_meta(runtime.store, "!chat1:example.org")
|
||||
assert room_meta is not None
|
||||
assert room_meta["chat_id"] == "C1"
|
||||
assert room_meta["space_id"] == "!space:example.org"
|
||||
|
||||
|
||||
async def test_mat02_invite_idempotent():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
client = _make_client()
|
||||
room = SimpleNamespace(room_id="!dm:example.org", display_name="Alice")
|
||||
event = SimpleNamespace(sender="@alice:example.org", membership="invite")
|
||||
|
||||
await handle_invite(client, room, event, runtime.platform, runtime.store, runtime.auth_mgr)
|
||||
await handle_invite(client, room, event, runtime.platform, runtime.store, runtime.auth_mgr)
|
||||
|
||||
assert client.room_create.await_count == 2
|
||||
|
||||
|
||||
async def test_mat03_no_hardcoded_c1():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
client = _make_client()
|
||||
room = SimpleNamespace(room_id="!dm:example.org", display_name="Alice")
|
||||
event = SimpleNamespace(sender="@alice:example.org", membership="invite")
|
||||
|
||||
await handle_invite(client, room, event, runtime.platform, runtime.store, runtime.auth_mgr)
|
||||
|
||||
room_meta = await get_room_meta(runtime.store, "!chat1:example.org")
|
||||
assert room_meta is not None
|
||||
assert room_meta["chat_id"] == "C1"
|
||||
|
||||
user_meta = await get_user_meta(runtime.store, "@alice:example.org")
|
||||
assert user_meta is not None
|
||||
assert user_meta["next_chat_index"] == 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue