test(feishu): cover media msg_type mapping

This commit is contained in:
Xubin Ren
2026-03-17 09:01:09 +00:00
committed by Xubin Ren
parent 47e2a1e8d7
commit 7086f57d05

View File

@@ -1,6 +1,7 @@
"""Tests for Feishu message reply (quote) feature.""" """Tests for Feishu message reply (quote) feature."""
import asyncio import asyncio
import json import json
from pathlib import Path
from types import SimpleNamespace from types import SimpleNamespace
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@@ -186,6 +187,48 @@ def test_reply_message_sync_returns_false_on_exception() -> None:
assert ok is False assert ok is False
@pytest.mark.asyncio
@pytest.mark.parametrize(
("filename", "expected_msg_type"),
[
("voice.opus", "audio"),
("clip.mp4", "video"),
("report.pdf", "file"),
],
)
async def test_send_uses_expected_feishu_msg_type_for_uploaded_files(
tmp_path: Path, filename: str, expected_msg_type: str
) -> None:
channel = _make_feishu_channel()
file_path = tmp_path / filename
file_path.write_bytes(b"demo")
send_calls: list[tuple[str, str, str, str]] = []
def _record_send(receive_id_type: str, receive_id: str, msg_type: str, content: str) -> None:
send_calls.append((receive_id_type, receive_id, msg_type, content))
with patch.object(channel, "_upload_file_sync", return_value="file-key"), patch.object(
channel, "_send_message_sync", side_effect=_record_send
):
await channel.send(
OutboundMessage(
channel="feishu",
chat_id="oc_test",
content="",
media=[str(file_path)],
metadata={},
)
)
assert len(send_calls) == 1
receive_id_type, receive_id, msg_type, content = send_calls[0]
assert receive_id_type == "chat_id"
assert receive_id == "oc_test"
assert msg_type == expected_msg_type
assert json.loads(content) == {"file_key": "file-key"}
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# send() — reply routing tests # send() — reply routing tests
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------