"""Tests for the Conversation Gateway.""" import pytest from loyal_companion.models.platform import ( ConversationContext, ConversationRequest, IntimacyLevel, Platform, ) from loyal_companion.services import ConversationGateway class TestConversationGateway: """Test suite for ConversationGateway.""" def test_gateway_initialization(self): """Test that the gateway initializes correctly.""" gateway = ConversationGateway() assert gateway is not None assert gateway.ai_service is not None def test_conversation_request_creation(self): """Test creating a ConversationRequest.""" request = ConversationRequest( user_id="12345", platform=Platform.DISCORD, session_id="channel-123", message="Hello!", context=ConversationContext( is_public=False, intimacy_level=IntimacyLevel.MEDIUM, guild_id="67890", channel_id="channel-123", user_display_name="TestUser", ), ) assert request.user_id == "12345" assert request.platform == Platform.DISCORD assert request.message == "Hello!" assert request.context.intimacy_level == IntimacyLevel.MEDIUM def test_intimacy_levels(self): """Test intimacy level enum values.""" assert IntimacyLevel.LOW == "low" assert IntimacyLevel.MEDIUM == "medium" assert IntimacyLevel.HIGH == "high" def test_platform_enum(self): """Test platform enum values.""" assert Platform.DISCORD == "discord" assert Platform.WEB == "web" assert Platform.CLI == "cli" def test_intimacy_modifier_low(self): """Test intimacy modifier for LOW intimacy.""" gateway = ConversationGateway() modifier = gateway._get_intimacy_modifier(Platform.DISCORD, IntimacyLevel.LOW) assert "PUBLIC, SOCIAL" in modifier assert "brief and light" in modifier assert "Avoid deep emotional topics" in modifier def test_intimacy_modifier_high(self): """Test intimacy modifier for HIGH intimacy.""" gateway = ConversationGateway() modifier = gateway._get_intimacy_modifier(Platform.CLI, IntimacyLevel.HIGH) assert "PRIVATE, INTENTIONAL" in modifier assert "Deeper reflection" in modifier assert "CRITICAL SAFETY BOUNDARIES" in modifier assert "Never claim exclusivity" in modifier def test_sentiment_estimation_positive(self): """Test sentiment estimation for positive messages.""" gateway = ConversationGateway() sentiment = gateway._estimate_sentiment("Thanks! This is awesome and amazing!") assert sentiment > 0.5 # Should be positive def test_sentiment_estimation_negative(self): """Test sentiment estimation for negative messages.""" gateway = ConversationGateway() sentiment = gateway._estimate_sentiment("This is terrible and awful, I hate it") assert sentiment < 0 # Should be negative def test_sentiment_estimation_neutral(self): """Test sentiment estimation for neutral messages.""" gateway = ConversationGateway() sentiment = gateway._estimate_sentiment("The weather is cloudy today") assert -0.5 < sentiment < 0.5 # Should be near neutral @pytest.mark.asyncio async def test_process_message_requires_database(self): """Test that process_message requires database.""" gateway = ConversationGateway() request = ConversationRequest( user_id="12345", platform=Platform.WEB, session_id="session-1", message="Hello", ) # Should raise ValueError if database not initialized with pytest.raises(ValueError, match="Database is required"): await gateway.process_message(request) if __name__ == "__main__": pytest.main([__file__, "-v"])