67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from unittest.mock import AsyncMock, MagicMock
|
|
import pytest
|
|
import discord
|
|
from chorus_bot.cogs.thread_ingest import ThreadIngestCog
|
|
from chorus_bot.ping import build_ping_embed
|
|
|
|
|
|
class _FakeConfig:
|
|
inbox_channel_id = 111
|
|
web_base_url = "https://chorus.circuitforge.tech"
|
|
|
|
|
|
def _make_thread(embed):
|
|
parent_message = MagicMock()
|
|
parent_message.embeds = [embed]
|
|
|
|
thread = MagicMock(spec=discord.Thread)
|
|
thread.id = 555
|
|
thread.parent_id = 111
|
|
thread.parent.fetch_message = AsyncMock(return_value=parent_message)
|
|
thread.send = AsyncMock()
|
|
return thread
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_thread_create_passes_direction_to_backend_client():
|
|
bot = MagicMock()
|
|
backend_client = AsyncMock()
|
|
backend_client.create_item.return_value = {"id": 42}
|
|
cog = ThreadIngestCog(bot, _FakeConfig(), backend_client)
|
|
|
|
embed = build_ping_embed(
|
|
modality="lead_found", sender_id=None, snippet="found post",
|
|
raw_content="Someone posting about book donation",
|
|
captured_at=__import__("datetime").datetime(2026, 7, 13, 7, 0, 0,
|
|
tzinfo=__import__("datetime").timezone.utc),
|
|
direction="outbound",
|
|
)
|
|
thread = _make_thread(embed)
|
|
|
|
await cog.on_thread_create(thread)
|
|
|
|
backend_client.create_item.assert_awaited_once()
|
|
assert backend_client.create_item.call_args.kwargs["direction"] == "outbound"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_thread_create_reply_includes_item_link():
|
|
bot = MagicMock()
|
|
backend_client = AsyncMock()
|
|
backend_client.create_item.return_value = {"id": 42}
|
|
cog = ThreadIngestCog(bot, _FakeConfig(), backend_client)
|
|
|
|
embed = build_ping_embed(
|
|
modality="lead_found", sender_id=None, snippet="found post",
|
|
raw_content="Someone posting about book donation",
|
|
captured_at=__import__("datetime").datetime(2026, 7, 13, 7, 0, 0,
|
|
tzinfo=__import__("datetime").timezone.utc),
|
|
direction="outbound",
|
|
)
|
|
thread = _make_thread(embed)
|
|
|
|
await cog.on_thread_create(thread)
|
|
|
|
thread.send.assert_awaited_once()
|
|
reply_text = thread.send.call_args.args[0]
|
|
assert "https://chorus.circuitforge.tech/?item=42" in reply_text
|