@@ -453,7 +453,9 @@ describe('submission.service', () => {
453453 form : mockForm ,
454454 recipientData,
455455 submission : MOCK_SUBMISSION ,
456- attachments : MOCK_ATTACHMENTS ,
456+ submissionAttachments : MOCK_ATTACHMENTS ,
457+ pdfAttachment : undefined ,
458+ isPaymentEnabled : false ,
457459 responsesData : MOCK_AUTOREPLY_DATA ,
458460 } )
459461
@@ -494,7 +496,9 @@ describe('submission.service', () => {
494496 form : mockForm ,
495497 recipientData,
496498 submission : MOCK_SUBMISSION ,
497- attachments : MOCK_ATTACHMENTS ,
499+ submissionAttachments : MOCK_ATTACHMENTS ,
500+ pdfAttachment : undefined ,
501+ isPaymentEnabled : false ,
498502 responsesData : MOCK_AUTOREPLY_DATA ,
499503 } )
500504
@@ -539,7 +543,9 @@ describe('submission.service', () => {
539543 form : mockForm ,
540544 recipientData,
541545 submission : MOCK_SUBMISSION ,
542- attachments : MOCK_ATTACHMENTS ,
546+ submissionAttachments : MOCK_ATTACHMENTS ,
547+ pdfAttachment : undefined ,
548+ isPaymentEnabled : false ,
543549 responsesData : MOCK_AUTOREPLY_DATA ,
544550 } )
545551
@@ -590,7 +596,9 @@ describe('submission.service', () => {
590596 form : mockForm ,
591597 recipientData,
592598 submission : MOCK_SUBMISSION ,
593- attachments : MOCK_ATTACHMENTS ,
599+ submissionAttachments : MOCK_ATTACHMENTS ,
600+ pdfAttachment : undefined ,
601+ isPaymentEnabled : false ,
594602 responsesData : MOCK_AUTOREPLY_DATA ,
595603 } )
596604
@@ -653,7 +661,9 @@ describe('submission.service', () => {
653661 form : mockForm ,
654662 recipientData,
655663 submission : MOCK_SUBMISSION ,
656- attachments : MOCK_ATTACHMENTS ,
664+ submissionAttachments : MOCK_ATTACHMENTS ,
665+ pdfAttachment : undefined ,
666+ isPaymentEnabled : false ,
657667 responsesData : undefined ,
658668 } )
659669
@@ -672,7 +682,82 @@ describe('submission.service', () => {
672682 expect ( result . _unsafeUnwrap ( ) ) . toBe ( true )
673683 } )
674684
675- it ( 'should call mail service with attachments undefined when there are no attachments' , async ( ) => {
685+ it ( 'should call mail service with pdfAttachment when a pdfAttachment is provided' , async ( ) => {
686+ const mockForm = {
687+ _id : MOCK_FORM_ID ,
688+ form_fields : [
689+ {
690+ ...generateDefaultField ( BasicField . Email ) ,
691+ autoReplyOptions : AUTOREPLY_OPTIONS_1 ,
692+ } ,
693+ {
694+ ...generateDefaultField ( BasicField . Email ) ,
695+ autoReplyOptions : AUTOREPLY_OPTIONS_2 ,
696+ } ,
697+ ] ,
698+ } as unknown as IPopulatedForm
699+ MockMailService . sendAutoReplyEmails . mockResolvedValueOnce ( [
700+ {
701+ status : 'fulfilled' ,
702+ value : ok ( true ) ,
703+ } ,
704+ {
705+ status : 'fulfilled' ,
706+ value : ok ( true ) ,
707+ } ,
708+ ] )
709+
710+ const responses = [
711+ {
712+ ...generateNewSingleAnswerResponse ( BasicField . Email , {
713+ _id : mockForm . form_fields ! [ 0 ] . _id ,
714+ answer : MOCK_EMAIL_1 ,
715+ } ) ,
716+ } ,
717+ {
718+ ...generateNewSingleAnswerResponse ( BasicField . Email , {
719+ _id : mockForm . form_fields ! [ 1 ] . _id ,
720+ answer : MOCK_EMAIL_2 ,
721+ } ) ,
722+ } ,
723+ ]
724+ const recipientData = extractEmailConfirmationData (
725+ responses ,
726+ mockForm . form_fields ,
727+ )
728+
729+ const MOCK_PDF_ATTACHMENT = {
730+ content : Buffer . from ( 'mock pdf buffer' ) ,
731+ filename : 'response.pdf' ,
732+ }
733+ const result = await SubmissionService . sendEmailConfirmations ( {
734+ form : mockForm ,
735+ recipientData,
736+ submission : MOCK_SUBMISSION ,
737+ submissionAttachments : undefined ,
738+ responsesData : MOCK_AUTOREPLY_DATA ,
739+ isPaymentEnabled : false ,
740+ pdfAttachment : MOCK_PDF_ATTACHMENT ,
741+ } )
742+
743+ const expectedAutoReplyData = [
744+ EXPECTED_AUTOREPLY_DATA_1 ,
745+ EXPECTED_AUTOREPLY_DATA_2 ,
746+ ]
747+
748+ expect ( MockMailService . sendAutoReplyEmails ) . toHaveBeenCalledWith ( {
749+ form : mockForm ,
750+ submission : MOCK_SUBMISSION ,
751+ submissionAttachments : undefined ,
752+ pdfAttachment : MOCK_PDF_ATTACHMENT ,
753+ isPaymentEnabled : false ,
754+ responsesData : MOCK_AUTOREPLY_DATA ,
755+ autoReplyMailDatas : expectedAutoReplyData ,
756+ } )
757+ expect ( result . _unsafeUnwrap ( ) ) . toBe ( true )
758+ } )
759+
760+ it ( 'should call mail service with submissionAttachments undefined and pdfAttachment undefined when there are no submissionAttachments or pdfAttachment' , async ( ) => {
676761 const mockForm = {
677762 _id : MOCK_FORM_ID ,
678763 form_fields : [
@@ -719,8 +804,10 @@ describe('submission.service', () => {
719804 form : mockForm ,
720805 recipientData,
721806 submission : MOCK_SUBMISSION ,
722- attachments : undefined ,
807+ submissionAttachments : undefined ,
723808 responsesData : MOCK_AUTOREPLY_DATA ,
809+ isPaymentEnabled : false ,
810+ pdfAttachment : undefined ,
724811 } )
725812
726813 const expectedAutoReplyData = [
@@ -731,7 +818,9 @@ describe('submission.service', () => {
731818 expect ( MockMailService . sendAutoReplyEmails ) . toHaveBeenCalledWith ( {
732819 form : mockForm ,
733820 submission : MOCK_SUBMISSION ,
734- attachments : undefined ,
821+ submissionAttachments : undefined ,
822+ pdfAttachment : undefined ,
823+ isPaymentEnabled : false ,
735824 responsesData : MOCK_AUTOREPLY_DATA ,
736825 autoReplyMailDatas : expectedAutoReplyData ,
737826 } )
@@ -786,8 +875,10 @@ describe('submission.service', () => {
786875 form : mockForm ,
787876 recipientData,
788877 submission : MOCK_SUBMISSION ,
789- attachments : MOCK_ATTACHMENTS ,
878+ submissionAttachments : MOCK_ATTACHMENTS ,
790879 responsesData : MOCK_AUTOREPLY_DATA ,
880+ isPaymentEnabled : false ,
881+ pdfAttachment : undefined ,
791882 } )
792883
793884 const expectedAutoReplyData = [
@@ -798,7 +889,9 @@ describe('submission.service', () => {
798889 expect ( MockMailService . sendAutoReplyEmails ) . toHaveBeenCalledWith ( {
799890 form : mockForm ,
800891 submission : MOCK_SUBMISSION ,
801- attachments : MOCK_ATTACHMENTS ,
892+ submissionAttachments : MOCK_ATTACHMENTS ,
893+ pdfAttachment : undefined ,
894+ isPaymentEnabled : false ,
802895 responsesData : MOCK_AUTOREPLY_DATA ,
803896 autoReplyMailDatas : expectedAutoReplyData ,
804897 } )
@@ -855,8 +948,10 @@ describe('submission.service', () => {
855948 form : mockForm ,
856949 recipientData,
857950 submission : MOCK_SUBMISSION ,
858- attachments : MOCK_ATTACHMENTS ,
951+ submissionAttachments : MOCK_ATTACHMENTS ,
859952 responsesData : MOCK_AUTOREPLY_DATA ,
953+ isPaymentEnabled : false ,
954+ pdfAttachment : undefined ,
860955 } )
861956
862957 const expectedAutoReplyData = [
@@ -867,9 +962,11 @@ describe('submission.service', () => {
867962 expect ( MockMailService . sendAutoReplyEmails ) . toHaveBeenCalledWith ( {
868963 form : mockForm ,
869964 submission : MOCK_SUBMISSION ,
870- attachments : MOCK_ATTACHMENTS ,
965+ submissionAttachments : MOCK_ATTACHMENTS ,
871966 responsesData : MOCK_AUTOREPLY_DATA ,
872967 autoReplyMailDatas : expectedAutoReplyData ,
968+ pdfAttachment : undefined ,
969+ isPaymentEnabled : false ,
873970 } )
874971 expect ( result . _unsafeUnwrapErr ( ) ) . toEqual (
875972 new SendEmailConfirmationError ( ) ,
@@ -2789,7 +2886,7 @@ describe('submission.service', () => {
27892886
27902887 // Act
27912888 // empty string for version id to simulate failure
2792- const actualResult = await downloadCleanFile ( MOCK_VALID_UUID , '' )
2889+ const actualResult = await downloadCleanFile ( MOCK_VALID_UUID , '' , 'mock-bucket-name' )
27932890
27942891 // Assert
27952892 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2824,7 +2921,7 @@ describe('submission.service', () => {
28242921
28252922 // Act
28262923 // empty strings for invalid keys and version ids
2827- const actualResult = await downloadCleanFile ( MOCK_VALID_UUID , versionId )
2924+ const actualResult = await downloadCleanFile ( MOCK_VALID_UUID , versionId , 'mock-bucket-name' )
28282925
28292926 // Assert
28302927 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
0 commit comments