|
3 | 3 |
|
4 | 4 | """Unit tests for send_chat_history method in McpToolServerConfigurationService.""" |
5 | 5 |
|
| 6 | +import json |
6 | 7 | from datetime import UTC, datetime |
7 | 8 | from unittest.mock import AsyncMock, MagicMock, Mock, patch |
8 | 9 |
|
@@ -146,14 +147,37 @@ async def test_send_chat_history_validates_chat_history_messages( |
146 | 147 | await service.send_chat_history(mock_turn_context, None) |
147 | 148 |
|
148 | 149 | @pytest.mark.asyncio |
149 | | - async def test_send_chat_history_empty_list_returns_success(self, service, mock_turn_context): |
150 | | - """Test that send_chat_history returns success for empty list (CRM-008).""" |
151 | | - # Act |
152 | | - result = await service.send_chat_history(mock_turn_context, []) |
153 | | - |
154 | | - # Assert - empty list should return success, not raise exception |
155 | | - assert result.succeeded is True |
156 | | - assert len(result.errors) == 0 |
| 150 | + async def test_send_chat_history_empty_list_sends_request(self, service, mock_turn_context): |
| 151 | + """Test that send_chat_history sends request to MCP platform even with empty list.""" |
| 152 | + # Arrange |
| 153 | + mock_response = AsyncMock() |
| 154 | + mock_response.status = 200 |
| 155 | + mock_response.text = AsyncMock(return_value="OK") |
| 156 | + |
| 157 | + # Mock aiohttp.ClientSession |
| 158 | + with patch("aiohttp.ClientSession") as mock_session: |
| 159 | + mock_session_instance = MagicMock() |
| 160 | + mock_post = AsyncMock() |
| 161 | + mock_post.__aenter__.return_value = mock_response |
| 162 | + mock_session_instance.post.return_value = mock_post |
| 163 | + mock_session.return_value.__aenter__.return_value = mock_session_instance |
| 164 | + |
| 165 | + # Act |
| 166 | + result = await service.send_chat_history(mock_turn_context, []) |
| 167 | + |
| 168 | + # Assert - empty list should still make HTTP request and return success |
| 169 | + assert result.succeeded is True |
| 170 | + assert len(result.errors) == 0 |
| 171 | + |
| 172 | + # Verify HTTP request was actually made |
| 173 | + assert mock_session_instance.post.called |
| 174 | + call_args = mock_session_instance.post.call_args |
| 175 | + assert "real-time-threat-protection/chat-message" in call_args[0][0] |
| 176 | + |
| 177 | + # Verify the payload contains an empty chat history |
| 178 | + data = call_args[1]["data"] |
| 179 | + payload = json.loads(data) |
| 180 | + assert payload["chatHistory"] == [] |
157 | 181 |
|
158 | 182 | @pytest.mark.asyncio |
159 | 183 | async def test_send_chat_history_validates_activity(self, service, chat_history_messages): |
|
0 commit comments