@@ -675,5 +675,58 @@ describe('Class: AsyncBatchProcessor', () => {
675
675
FullBatchFailureError
676
676
) ;
677
677
} ) ;
678
+
679
+ it ( 'uses a custom logger when provided' , async ( ) => {
680
+ // Prepare
681
+ const logger = {
682
+ debug : vi . fn ( ) ,
683
+ info : vi . fn ( ) ,
684
+ warn : vi . fn ( ) ,
685
+ error : vi . fn ( ) ,
686
+ } ;
687
+ const unsupportedSchema = v . object ( {
688
+ Message : v . string ( ) ,
689
+ } ) ;
690
+ const firstRecord = sqsRecordFactory ( JSON . stringify ( successPayload1 ) ) ;
691
+ const secondRecord = sqsRecordFactory ( JSON . stringify ( successPayload2 ) ) ;
692
+ const records = [ firstRecord , secondRecord ] ;
693
+ const processor = new BatchProcessor ( EventType . SQS , {
694
+ innerSchema : unsupportedSchema ,
695
+ transformer : 'json' ,
696
+ logger,
697
+ } ) ;
698
+
699
+ // Act
700
+ processor . register ( records , sqsRecordHandler , options ) ;
701
+
702
+ // Assess
703
+ await expect ( processor . process ( ) ) . rejects . toThrowError (
704
+ FullBatchFailureError
705
+ ) ;
706
+ expect ( logger . error ) . toHaveBeenCalledWith (
707
+ 'The schema provided is not supported. Only Zod schemas are supported for extension.'
708
+ ) ;
709
+ } ) ;
710
+
711
+ it ( 'emits debug logs when AWS_LAMBDA_LOG_LEVEL is set to DEBUG' , async ( ) => {
712
+ // Prepare
713
+ const consoleSpy = vi . spyOn ( console , 'debug' ) ;
714
+ vi . stubEnv ( 'AWS_LAMBDA_LOG_LEVEL' , 'DEBUG' ) ;
715
+ const firstRecord = sqsRecordFactory ( JSON . stringify ( failurePayload1 ) ) ;
716
+ const records = [ firstRecord ] ;
717
+ const processor = new BatchProcessor ( EventType . SQS , {
718
+ innerSchema : customSchema ,
719
+ transformer : 'json' ,
720
+ } ) ;
721
+
722
+ // Act
723
+ processor . register ( records , sqsRecordHandler , options ) ;
724
+
725
+ // Assess
726
+ await expect ( processor . process ( ) ) . rejects . toThrowError (
727
+ FullBatchFailureError
728
+ ) ;
729
+ expect ( consoleSpy ) . toHaveBeenCalled ( ) ;
730
+ } ) ;
678
731
} ) ;
679
732
} ) ;
0 commit comments