|
@@ -3550,6 +3550,53 @@ class TestPluginToolHandlers:
|
|
|
assert result["success"] is True
|
|
assert result["success"] is True
|
|
|
assert result["dm_room_id"] == "dm-user-1"
|
|
assert result["dm_room_id"] == "dm-user-1"
|
|
|
|
|
|
|
|
|
|
+ async def test_send_dm_finds_a_dm_room_the_directory_omits_members_for(self):
|
|
|
|
|
+ """`member_user_ids` is not part of the documented ListRooms response, so
|
|
|
|
|
+ a server may leave it empty. A DM room the bot can see plainly exists,
|
|
|
|
|
+ and refusing with "no DM exists yet" would send the user looking for a
|
|
|
|
|
+ message they never have to send.
|
|
|
|
|
+ """
|
|
|
|
|
+ client = self._stub_client()
|
|
|
|
|
+ client.list_rooms = AsyncMock(
|
|
|
|
|
+ return_value=[_make_room_state(_make_room("dm-user-1", "", RoomKind.DM))]
|
|
|
|
|
+ )
|
|
|
|
|
+ client.list_room_members = AsyncMock(
|
|
|
|
|
+ return_value=(["bot-user-id", "user-1"], Page())
|
|
|
|
|
+ )
|
|
|
|
|
+ result, _, _ = await self._run(
|
|
|
|
|
+ _handle_chatto_send_dm,
|
|
|
|
|
+ {"user_id": "user-1", "message": "hi"},
|
|
|
|
|
+ client=client,
|
|
|
|
|
+ )
|
|
|
|
|
+ assert result["success"] is True
|
|
|
|
|
+ assert result["dm_room_id"] == "dm-user-1"
|
|
|
|
|
+
|
|
|
|
|
+ async def test_send_dm_resolves_a_login_the_directory_omits_members_for(self):
|
|
|
|
|
+ """The same empty field also gated the login search: a room whose
|
|
|
|
|
+ membership the directory did not report was skipped outright, so the
|
|
|
|
|
+ login was unfindable even though the DM room sits right there."""
|
|
|
|
|
+ client = self._stub_client()
|
|
|
|
|
+ client.list_rooms = AsyncMock(
|
|
|
|
|
+ return_value=[_make_room_state(_make_room("dm-user-1", "", RoomKind.DM))]
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # A search narrows the result; an unsearched call lists the whole
|
|
|
|
|
+ # room, which is what the DM-room lookup then asks for.
|
|
|
|
|
+ async def _members(room_id, *, search="", **kwargs):
|
|
|
|
|
+ return (["user-1"] if search else ["bot-user-id", "user-1"], Page())
|
|
|
|
|
+
|
|
|
|
|
+ client.list_room_members = AsyncMock(side_effect=_members)
|
|
|
|
|
+ client.batch_get_room_members = AsyncMock(
|
|
|
|
|
+ return_value=[DirectoryMember(user=_make_user("user-1", "Alice"))]
|
|
|
|
|
+ )
|
|
|
|
|
+ result, _, _ = await self._run(
|
|
|
|
|
+ _handle_chatto_send_dm,
|
|
|
|
|
+ {"user_login": "alice", "message": "hi"},
|
|
|
|
|
+ client=client,
|
|
|
|
|
+ )
|
|
|
|
|
+ assert result["success"] is True
|
|
|
|
|
+ assert result["recipient_user_id"] == "user-1"
|
|
|
|
|
+
|
|
|
async def test_send_dm_resolves_a_login_in_the_shared_dm_room(self):
|
|
async def test_send_dm_resolves_a_login_in_the_shared_dm_room(self):
|
|
|
"""A login is looked up in the rooms we share, not in an admin-only
|
|
"""A login is looked up in the rooms we share, not in an admin-only
|
|
|
server-wide directory the bot cannot read."""
|
|
server-wide directory the bot cannot read."""
|