"""Tests for the Discord module.""" from src.discord import split_content, build_components def test_split_content_short() -> None: """Test that short content is not split.""" content = "Hello, world!" result = split_content(content) assert len(result) == 1 assert result[0] == content def test_split_content_long() -> None: """Test that long content is split correctly.""" content = "x" * 2500 result = split_content(content, max_length=2000) assert len(result) == 2 assert "[Part 1/2]" in result[0] assert "[Part 2/2]" in result[1] def test_split_content_preserves_newlines() -> None: """Test that content is split on newlines when possible.""" content = "\n".join(["Line " + str(i) for i in range(100)]) result = split_content(content, max_length=500) assert len(result) > 1 # Each part should have complete lines for part in result: assert "Line" in part def test_build_components() -> None: """Test that components are built correctly.""" components = build_components( post_url="https://truthsocial.com/@user/posts/123", post_id="123", raw_json='{"id": "123"}', ) assert len(components) == 1 assert components[0]["type"] == 1 # Action Row buttons = components[0]["components"] assert len(buttons) == 3 # Delete button assert buttons[0]["type"] == 2 assert buttons[0]["style"] == 4 # Danger assert buttons[0]["label"] == "Delete" # View Raw button assert buttons[1]["type"] == 2 assert buttons[1]["style"] == 2 # Secondary assert buttons[1]["label"] == "View Raw" # Original Post button (link) assert buttons[2]["type"] == 2 assert buttons[2]["style"] == 5 # Link assert buttons[2]["url"] == "https://truthsocial.com/@user/posts/123"