@@ -20,7 +20,7 @@ jest.unstable_mockModule('../../files.js', () => ({
2020 } ,
2121} ) ) ;
2222
23- const mockSend = jest . fn ( ) . mockResolvedValue ( { id : 'email_123' } ) ;
23+ const mockSend = jest . fn ( ) . mockResolvedValue ( { id : 'email_123' , accepted : [ 'user@example.com' ] , rejected : [ ] } ) ;
2424jest . unstable_mockModule ( '../provider.resend.js' , ( ) => ( {
2525 default : jest . fn ( ) . mockImplementation ( ( ) => ( { send : mockSend } ) ) ,
2626} ) ) ;
@@ -40,7 +40,7 @@ describe('mailer index with resend provider unit tests:', () => {
4040 expect ( mailer . isConfigured ( ) ) . toBe ( true ) ;
4141 } ) ;
4242
43- test ( 'should send mail using the resend provider' , async ( ) => {
43+ test ( 'should send mail using the resend provider and normalize response ' , async ( ) => {
4444 mockSend . mockResolvedValue ( { id : 'email_456' } ) ;
4545
4646 const result = await mailer . sendMail ( {
@@ -58,10 +58,42 @@ describe('mailer index with resend provider unit tests:', () => {
5858 html : '<p>Alice</p>' ,
5959 } ) ,
6060 ) ;
61- expect ( result ) . toEqual ( { id : 'email_456' } ) ;
61+ expect ( result ) . toEqual ( { id : 'email_456' , accepted : [ 'user@example.com' ] , rejected : [ ] } ) ;
6262 } ) ;
6363
64- test ( 'should return null on send error' , async ( ) => {
64+ test ( 'should pass through response unchanged when accepted is already an array' , async ( ) => {
65+ mockSend . mockResolvedValue ( { id : 'email_789' , accepted : [ 'user@example.com' ] , rejected : [ ] } ) ;
66+
67+ const result = await mailer . sendMail ( {
68+ to : 'user@example.com' ,
69+ subject : 'Welcome' ,
70+ template : 'welcome' ,
71+ params : { name : 'Charlie' } ,
72+ } ) ;
73+
74+ expect ( result ) . toEqual ( { id : 'email_789' , accepted : [ 'user@example.com' ] , rejected : [ ] } ) ;
75+ } ) ;
76+
77+ test ( 'should forward attachments to the provider' , async ( ) => {
78+ mockSend . mockResolvedValue ( { id : 'email_attach' , accepted : [ 'user@example.com' ] , rejected : [ ] } ) ;
79+
80+ const attachments = [ { filename : 'report.csv' , content : 'a,b\n1,2' } ] ;
81+ await mailer . sendMail ( {
82+ to : 'user@example.com' ,
83+ subject : 'Report' ,
84+ template : 'welcome' ,
85+ params : { name : 'Carol' } ,
86+ attachments,
87+ } ) ;
88+
89+ expect ( mockSend ) . toHaveBeenCalledWith (
90+ expect . objectContaining ( {
91+ attachments,
92+ } ) ,
93+ ) ;
94+ } ) ;
95+
96+ test ( 'should return null on send error' , async ( ) => {
6597 mockSend . mockRejectedValue ( new Error ( 'API failure' ) ) ;
6698
6799 const result = await mailer . sendMail ( {
0 commit comments