fix: make matrix entry-room bootstrap idempotent
This commit is contained in:
parent
17d580096b
commit
c666d908da
2 changed files with 65 additions and 0 deletions
|
|
@ -260,6 +260,39 @@ async def test_unregistered_room_bootstraps_space_and_chat_on_first_message():
|
|||
room_send_calls = client.room_send.await_args_list
|
||||
assert any(call.args[0] == "!chat1:example.org" for call in room_send_calls)
|
||||
assert any(call.args[0] == "!entry:example.org" for call in room_send_calls)
|
||||
entry_meta = await get_room_meta(runtime.store, "!entry:example.org")
|
||||
assert entry_meta == {
|
||||
"matrix_user_id": "@alice:example.org",
|
||||
"redirect_room_id": "!chat1:example.org",
|
||||
"redirect_chat_id": "C1",
|
||||
}
|
||||
|
||||
|
||||
async def test_unregistered_room_second_message_reuses_existing_bootstrap():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
await set_user_meta(runtime.store, "@alice:example.org", {"next_chat_index": 1})
|
||||
space_resp = SimpleNamespace(room_id="!space:example.org")
|
||||
chat_resp = SimpleNamespace(room_id="!chat1:example.org")
|
||||
client = SimpleNamespace(
|
||||
user_id="@bot:example.org",
|
||||
room_create=AsyncMock(side_effect=[space_resp, chat_resp]),
|
||||
room_put_state=AsyncMock(),
|
||||
room_send=AsyncMock(),
|
||||
)
|
||||
bot = MatrixBot(client, runtime)
|
||||
room = SimpleNamespace(room_id="!entry:example.org", display_name="Entry")
|
||||
|
||||
await bot.on_room_message(room, SimpleNamespace(sender="@alice:example.org", body="hello"))
|
||||
await bot.on_room_message(room, SimpleNamespace(sender="@alice:example.org", body="hello again"))
|
||||
|
||||
assert client.room_create.await_count == 2
|
||||
room_send_calls = client.room_send.await_args_list
|
||||
assert any(call.args[0] == "!entry:example.org" for call in room_send_calls)
|
||||
assert any(
|
||||
call.args[0] == "!entry:example.org"
|
||||
and "Рабочий чат уже создан: C1" in call.args[2]["body"]
|
||||
for call in room_send_calls
|
||||
)
|
||||
|
||||
|
||||
async def test_unregistered_room_creates_new_chat_in_existing_space():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue