from __future__ import annotations import pytest from yuxi.channels.adapters.mattermost.session import ( resolve_chat_id, resolve_chat_type, ) from yuxi.channels.models import ChatType class TestResolveChatId: def test_dm_channel(self): assert resolve_chat_id( {"user_id": "U001", "channel_id": "abc"}, {"type": "D"}, ) == "dm_U001" def test_dm_without_user_id(self): assert resolve_chat_id( {"channel_id": "abc"}, {"type": "D"}, ) == "dm_unknown" def test_public_channel(self): assert resolve_chat_id( {"channel_id": "ch123"}, {"type": "O"}, ) == "channel_ch123" def test_private_channel(self): assert resolve_chat_id( {"channel_id": "ch456"}, {"type": "P"}, ) == "channel_ch456" def test_thread_message(self): assert resolve_chat_id( {"channel_id": "ch123", "root_id": "post1"}, {"type": "O"}, ) == "channel_ch123:thread_post1" def test_thread_priority_over_dm(self): assert resolve_chat_id( {"channel_id": "abc", "root_id": "post1", "user_id": "U001"}, {"type": "D"}, ) == "channel_abc:thread_post1" class TestResolveChatType: def test_direct_message(self): assert resolve_chat_type({}, {"type": "D"}) == ChatType.DIRECT def test_thread(self): assert resolve_chat_type( {"root_id": "post1"}, {"type": "O"}, ) == ChatType.THREAD def test_thread_priority_over_dm(self): assert resolve_chat_type( {"root_id": "post1"}, {"type": "D"}, ) == ChatType.THREAD def test_public_channel(self): assert resolve_chat_type({}, {"type": "O"}) == ChatType.GROUP def test_private_channel(self): assert resolve_chat_type({}, {"type": "P"}) == ChatType.GROUP def test_missing_type_defaults_to_group(self): assert resolve_chat_type({}, {}) == ChatType.GROUP