@@ -171,6 +171,52 @@ def test_check_feedback_exists(mock_table, mock_env):
171171 assert result is False
172172
173173
174+ @patch ("app.slack.slack_events.table" )
175+ @patch ("time.time" )
176+ def test_store_feedback_no_message_ts_fallback (mock_time , mock_table , mock_env ):
177+ """Test store_feedback fallback path when no message_ts"""
178+ mock_time .return_value = 1000
179+ from app .slack .slack_events import store_feedback
180+
181+ with patch ("app.slack.slack_events.get_latest_message_ts" , return_value = None ):
182+ store_feedback ("conv-key" , "query" , "positive" , "user-id" , "channel-id" )
183+ mock_table .put_item .assert_called_once ()
184+ # Should use fallback pk/sk format without condition
185+ call_args = mock_table .put_item .call_args [1 ]
186+ assert "ConditionExpression" not in call_args
187+ item = call_args ["Item" ]
188+ assert item ["pk" ] == "feedback#conv-key"
189+ assert "#note#" in item ["sk" ]
190+
191+
192+ @patch ("app.slack.slack_events.table" )
193+ @patch ("time.time" )
194+ def test_store_conversation_session_with_thread (mock_time , mock_table , mock_env ):
195+ """Test store_conversation_session with thread_ts"""
196+ mock_time .return_value = 1000
197+ from app .slack .slack_events import store_conversation_session
198+
199+ store_conversation_session ("conv-key" , "session-id" , "user-id" , "channel-id" , "thread-123" , "msg-456" )
200+ mock_table .put_item .assert_called_once ()
201+ item = mock_table .put_item .call_args [1 ]["Item" ]
202+ assert item ["thread_ts" ] == "thread-123"
203+ assert item ["latest_message_ts" ] == "msg-456"
204+
205+
206+ @patch ("app.slack.slack_events.table" )
207+ @patch ("time.time" )
208+ def test_store_conversation_session_without_thread (mock_time , mock_table , mock_env ):
209+ """Test store_conversation_session without thread_ts"""
210+ mock_time .return_value = 1000
211+ from app .slack .slack_events import store_conversation_session
212+
213+ store_conversation_session ("conv-key" , "session-id" , "user-id" , "channel-id" )
214+ mock_table .put_item .assert_called_once ()
215+ item = mock_table .put_item .call_args [1 ]["Item" ]
216+ assert "thread_ts" not in item
217+ assert "latest_message_ts" not in item
218+
219+
174220@patch ("app.slack.slack_events.table" )
175221def test_cleanup_previous_unfeedback_qa_error_handling (mock_table , mock_env ):
176222 """Test cleanup_previous_unfeedback_qa error handling"""
@@ -215,3 +261,28 @@ def test_store_feedback_client_error_reraise(mock_table, mock_env):
215261 with patch ("app.slack.slack_events.get_latest_message_ts" , return_value = "123" ):
216262 with pytest .raises (ClientError ):
217263 store_feedback ("conv-key" , "query" , "positive" , "user-id" , "channel-id" )
264+
265+
266+ def test_feedback_text_extraction (mock_env ):
267+ """Test feedback text extraction logic"""
268+ # Test the specific logic: note = text.split(":", 1)[1].strip() if ":" in text else ""
269+
270+ # Test with colon - should extract text after colon
271+ text = "feedback: some feedback text"
272+ note = text .split (":" , 1 )[1 ].strip () if ":" in text else ""
273+ assert note == "some feedback text"
274+
275+ # Test without colon - should use empty string
276+ text = "feedback"
277+ note = text .split (":" , 1 )[1 ].strip () if ":" in text else ""
278+ assert note == ""
279+
280+ # Test with colon but no text after
281+ text = "feedback:"
282+ note = text .split (":" , 1 )[1 ].strip () if ":" in text else ""
283+ assert note == ""
284+
285+ # Test with colon and whitespace
286+ text = "feedback: "
287+ note = text .split (":" , 1 )[1 ].strip () if ":" in text else ""
288+ assert note == ""
0 commit comments