61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from yuxi.channels.adapters.slack.session import (
|
||
|
|
resolve_chat_id,
|
||
|
|
resolve_chat_type,
|
||
|
|
extract_thread_ts,
|
||
|
|
)
|
||
|
|
from yuxi.channels.models import ChatType
|
||
|
|
|
||
|
|
|
||
|
|
class TestResolveChatId:
|
||
|
|
def test_dm_channel_prefix(self):
|
||
|
|
assert resolve_chat_id("D1234567", {"user": "U001"}) == "dm_U001"
|
||
|
|
|
||
|
|
def test_im_channel_type(self):
|
||
|
|
assert resolve_chat_id("C1234567", {"channel_type": "im", "user": "U001"}) == "dm_U001"
|
||
|
|
|
||
|
|
def test_public_channel(self):
|
||
|
|
assert resolve_chat_id("C1234567", {}) == "channel_C1234567"
|
||
|
|
|
||
|
|
def test_private_channel(self):
|
||
|
|
assert resolve_chat_id("G1234567", {}) == "channel_G1234567"
|
||
|
|
|
||
|
|
def test_dm_without_user(self):
|
||
|
|
assert resolve_chat_id("D1234567", {}) == "dm_unknown"
|
||
|
|
|
||
|
|
|
||
|
|
class TestResolveChatType:
|
||
|
|
def test_dm_prefix(self):
|
||
|
|
assert resolve_chat_type("D1234567", {}) == ChatType.DIRECT
|
||
|
|
|
||
|
|
def test_im_type(self):
|
||
|
|
assert resolve_chat_type("C1234567", {"channel_type": "im"}) == ChatType.DIRECT
|
||
|
|
|
||
|
|
def test_thread(self):
|
||
|
|
assert resolve_chat_type("C1234567", {"thread_ts": "111.222", "ts": "333.444"}) == ChatType.THREAD
|
||
|
|
|
||
|
|
def test_thread_same_ts(self):
|
||
|
|
assert resolve_chat_type("C1234567", {"thread_ts": "111.222", "ts": "111.222"}) == ChatType.GROUP
|
||
|
|
|
||
|
|
def test_group_default(self):
|
||
|
|
assert resolve_chat_type("C1234567", {}) == ChatType.GROUP
|
||
|
|
|
||
|
|
def test_private_channel(self):
|
||
|
|
assert resolve_chat_type("G1234567", {}) == ChatType.GROUP
|
||
|
|
|
||
|
|
|
||
|
|
class TestExtractThreadTs:
|
||
|
|
def test_thread_message(self):
|
||
|
|
assert extract_thread_ts({"thread_ts": "111.222", "ts": "333.444"}) == "111.222"
|
||
|
|
|
||
|
|
def test_parent_message(self):
|
||
|
|
assert extract_thread_ts({"thread_ts": "111.222", "ts": "111.222"}) is None
|
||
|
|
|
||
|
|
def test_no_thread(self):
|
||
|
|
assert extract_thread_ts({"ts": "111.222"}) is None
|
||
|
|
|
||
|
|
def test_empty_event(self):
|
||
|
|
assert extract_thread_ts({}) is None
|