@@ -261,3 +261,114 @@ def test_handle_direct_message(mock_boto_resource, mock_get_parameter, mock_app,
261261 from app import handle_direct_message
262262
263263 assert callable (handle_direct_message )
264+
265+
266+ @patch ("slack_bolt.App" )
267+ @patch ("aws_lambda_powertools.utilities.parameters.get_parameter" )
268+ @patch ("boto3.resource" )
269+ def test_process_async_slack_event_exists (mock_boto_resource , mock_get_parameter , mock_app , mock_env ):
270+ """Test process_async_slack_event function exists and is callable"""
271+ mock_get_parameter .side_effect = [
272+ json .dumps ({"token" : "test-token" }),
273+ json .dumps ({"secret" : "test-secret" }),
274+ ]
275+ mock_boto_resource .return_value .Table .return_value = Mock ()
276+
277+ if "app" in sys .modules :
278+ del sys .modules ["app" ]
279+
280+ from app import process_async_slack_event
281+
282+ assert callable (process_async_slack_event )
283+
284+
285+ @patch ("botocore.exceptions.ClientError" )
286+ @patch ("slack_bolt.App" )
287+ @patch ("aws_lambda_powertools.utilities.parameters.get_parameter" )
288+ @patch ("boto3.resource" )
289+ def test_is_duplicate_event_client_error (mock_boto_resource , mock_get_parameter , mock_app , mock_client_error , mock_env ):
290+ """Test is_duplicate_event handles ClientError"""
291+ mock_get_parameter .side_effect = [
292+ json .dumps ({"token" : "test-token" }),
293+ json .dumps ({"secret" : "test-secret" }),
294+ ]
295+ mock_table = Mock ()
296+ mock_boto_resource .return_value .Table .return_value = mock_table
297+ mock_table .get_item .side_effect = mock_client_error
298+
299+ if "app" in sys .modules :
300+ del sys .modules ["app" ]
301+
302+ from app import is_duplicate_event
303+
304+ result = is_duplicate_event ("test-event" )
305+ assert result is False
306+
307+
308+ @patch ("botocore.exceptions.ClientError" )
309+ @patch ("slack_bolt.App" )
310+ @patch ("aws_lambda_powertools.utilities.parameters.get_parameter" )
311+ @patch ("boto3.resource" )
312+ @patch ("time.time" )
313+ def test_mark_event_processed_client_error (
314+ mock_time , mock_boto_resource , mock_get_parameter , mock_app , mock_client_error , mock_env
315+ ):
316+ """Test mark_event_processed handles ClientError"""
317+ mock_get_parameter .side_effect = [
318+ json .dumps ({"token" : "test-token" }),
319+ json .dumps ({"secret" : "test-secret" }),
320+ ]
321+ mock_table = Mock ()
322+ mock_boto_resource .return_value .Table .return_value = mock_table
323+ mock_table .put_item .side_effect = mock_client_error
324+ mock_time .return_value = 1000
325+
326+ if "app" in sys .modules :
327+ del sys .modules ["app" ]
328+
329+ from app import mark_event_processed
330+
331+ # Should not raise exception
332+ mark_event_processed ("test-event" )
333+
334+
335+ @patch ("slack_bolt.App" )
336+ @patch ("aws_lambda_powertools.utilities.parameters.get_parameter" )
337+ @patch ("boto3.resource" )
338+ def test_is_duplicate_event_no_item (mock_boto_resource , mock_get_parameter , mock_app , mock_env ):
339+ """Test is_duplicate_event when no item exists"""
340+ mock_get_parameter .side_effect = [
341+ json .dumps ({"token" : "test-token" }),
342+ json .dumps ({"secret" : "test-secret" }),
343+ ]
344+ mock_table = Mock ()
345+ mock_boto_resource .return_value .Table .return_value = mock_table
346+ mock_table .get_item .return_value = {} # No Item key
347+
348+ if "app" in sys .modules :
349+ del sys .modules ["app" ]
350+
351+ from app import is_duplicate_event
352+
353+ result = is_duplicate_event ("test-event" )
354+ assert result is False
355+
356+
357+ @patch ("slack_bolt.App" )
358+ @patch ("aws_lambda_powertools.utilities.parameters.get_parameter" )
359+ @patch ("boto3.resource" )
360+ @patch ("re.sub" )
361+ def test_regex_text_processing (mock_re_sub , mock_boto_resource , mock_get_parameter , mock_app , mock_env ):
362+ """Test regex processing in process_async_slack_event"""
363+ mock_get_parameter .side_effect = [
364+ json .dumps ({"token" : "test-token" }),
365+ json .dumps ({"secret" : "test-secret" }),
366+ ]
367+ mock_boto_resource .return_value .Table .return_value = Mock ()
368+ mock_re_sub .return_value = "cleaned text"
369+
370+ if "app" in sys .modules :
371+ del sys .modules ["app" ]
372+
373+ # Verify re.sub is available for import
374+ assert mock_re_sub is not None
0 commit comments