@@ -147,11 +147,11 @@ describe('ApiMailAdapter', () => {
147147
148148 await adapter . sendPasswordResetEmail ( options ) ;
149149 expect ( _sendMail . calls . all ( ) [ 0 ] . args [ 0 ] ) . toEqual ( expectedArguments ) ;
150- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . from ) . toEqual ( config . sender ) ;
151- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . to ) . toEqual ( user . get ( 'email' ) ) ;
152- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . subject ) . toMatch ( "Reset" ) ;
153- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . text ) . toMatch ( "reset" ) ;
154- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . html ) . toMatch ( "reset" ) ;
150+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . from ) . toEqual ( config . sender ) ;
151+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . to ) . toEqual ( user . get ( 'email' ) ) ;
152+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . subject ) . toMatch ( "Reset" ) ;
153+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . text ) . toMatch ( "reset" ) ;
154+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . html ) . toMatch ( "reset" ) ;
155155 } ) ;
156156 } ) ;
157157
@@ -175,11 +175,11 @@ describe('ApiMailAdapter', () => {
175175
176176 await adapter . sendVerificationEmail ( options ) ;
177177 expect ( _sendMail . calls . all ( ) [ 0 ] . args [ 0 ] ) . toEqual ( expectedArguments ) ;
178- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . from ) . toEqual ( config . sender ) ;
179- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . to ) . toEqual ( user . get ( 'email' ) ) ;
180- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . subject ) . toMatch ( "Verification" ) ;
181- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . text ) . toMatch ( "verify" ) ;
182- expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . html ) . toMatch ( "verify" ) ;
178+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . from ) . toEqual ( config . sender ) ;
179+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . to ) . toEqual ( user . get ( 'email' ) ) ;
180+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . subject ) . toMatch ( "Verification" ) ;
181+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . text ) . toMatch ( "verify" ) ;
182+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . html ) . toMatch ( "verify" ) ;
183183 } ) ;
184184 } ) ;
185185
@@ -216,7 +216,7 @@ describe('ApiMailAdapter', () => {
216216 it ( 'creates payload with correct properties' , async ( ) => {
217217 const adapter = new ApiMailAdapter ( config ) ;
218218 spyOn ( adapter , 'apiCallback' ) . and . callFake ( apiResponseSuccess ) ;
219- const _createPayload = spyOn ( adapter , '_createPayload ' ) . and . callThrough ( ) ;
219+ const _createApiData = spyOn ( adapter , '_createApiData ' ) . and . callThrough ( ) ;
220220 const options = {
221221 sender : config . sender ,
222222@@ -235,7 +235,7 @@ describe('ApiMailAdapter', () => {
235235
236236 await expectAsync ( adapter . sendMail ( options ) ) . toBeResolved ( ) ;
237237
238- const payload = ( await _createPayload . calls . all ( ) [ 0 ] . returnValue ) ;
238+ const { payload } = ( await _createApiData . calls . all ( ) [ 0 ] . returnValue ) ;
239239 expect ( payload . from ) . toMatch ( options . sender ) ;
240240 expect ( payload . to ) . toMatch ( options . recipient ) ;
241241 expect ( payload . subject ) . toMatch ( options . subject ) ;
@@ -247,7 +247,7 @@ describe('ApiMailAdapter', () => {
247247 it ( 'creates payload with correct properties when overriding extras' , async ( ) => {
248248 const adapter = new ApiMailAdapter ( config ) ;
249249 spyOn ( adapter , 'apiCallback' ) . and . callFake ( apiResponseSuccess ) ;
250- const _createPayload = spyOn ( adapter , '_createPayload ' ) . and . callThrough ( ) ;
250+ const _createApiData = spyOn ( adapter , '_createApiData ' ) . and . callThrough ( ) ;
251251 const options = {
252252 sender : config . sender ,
253253@@ -266,7 +266,7 @@ describe('ApiMailAdapter', () => {
266266
267267 await expectAsync ( adapter . sendMail ( options ) ) . toBeResolved ( ) ;
268268
269- const payload = ( await _createPayload . calls . all ( ) [ 0 ] . returnValue ) ;
269+ const { payload } = ( await _createApiData . calls . all ( ) [ 0 ] . returnValue ) ;
270270 expect ( payload . from ) . toMatch ( options . sender ) ;
271271 expect ( payload . to ) . toMatch ( options . recipient ) ;
272272 expect ( payload . subject ) . toMatch ( options . subject ) ;
@@ -349,7 +349,7 @@ describe('ApiMailAdapter', () => {
349349 const _loadFile = spyOn ( adapter , '_loadFile' ) . and . callThrough ( ) ;
350350 const options = { message : { } , template : config . templates . customEmail } ;
351351
352- await adapter . _createPayload ( options ) ;
352+ await adapter . _createApiData ( options ) ;
353353 const subjectFileData = await fs . readFile ( options . template . subjectPath ) ;
354354 const textFileData = await fs . readFile ( options . template . textPath ) ;
355355 const htmlFileData = await fs . readFile ( options . template . htmlPath ) ;
@@ -371,7 +371,7 @@ describe('ApiMailAdapter', () => {
371371 placeholders : { appName : 'ExampleApp' }
372372 } ;
373373
374- await adapter . _createPayload ( options ) ;
374+ await adapter . _createApiData ( options ) ;
375375
376376 expect ( _fillPlaceholders . calls . all ( ) [ 0 ] . args [ 0 ] ) . not . toContain ( 'ExampleApp' ) ;
377377 expect ( _fillPlaceholders . calls . all ( ) [ 1 ] . args [ 0 ] ) . not . toContain ( 'ExampleApp' ) ;
@@ -418,10 +418,11 @@ describe('ApiMailAdapter', () => {
418418 describe ( 'localization' , ( ) => {
419419 let adapter ;
420420 let options ;
421+ let apiCallback ;
421422
422423 beforeEach ( async ( ) => {
423424 adapter = new ApiMailAdapter ( config ) ;
424- spyOn ( adapter , 'apiCallback' ) . and . callFake ( apiResponseSuccess ) ;
425+ apiCallback = spyOn ( adapter , 'apiCallback' ) . and . callFake ( apiResponseSuccess ) ;
425426
426427 options = {
427428 message : { } ,
@@ -432,7 +433,7 @@ describe('ApiMailAdapter', () => {
432433
433434 it ( 'uses user locale variable from user locale callback' , async ( ) => {
434435 const _loadFile = spyOn ( adapter , '_loadFile' ) . and . callThrough ( ) ;
435- await adapter . _createPayload ( options ) ;
436+ await adapter . _createApiData ( options ) ;
436437
437438 const subjectFileData = await fs . readFile ( path . join ( __dirname , 'templates/de-AT/custom_email_subject.txt' ) ) ;
438439 const textFileData = await fs . readFile ( path . join ( __dirname , 'templates/de-AT/custom_email.txt' ) ) ;
@@ -452,7 +453,7 @@ describe('ApiMailAdapter', () => {
452453 return ! / \/ t e m p l a t e s \/ d e - A T \/ / . test ( path ) ;
453454 } ) ;
454455 const _loadFile = spyOn ( adapter , '_loadFile' ) . and . callThrough ( ) ;
455- await adapter . _createPayload ( options ) ;
456+ await adapter . _createApiData ( options ) ;
456457
457458 const subjectFileData = await fs . readFile ( path . join ( __dirname , 'templates/de/custom_email_subject.txt' ) ) ;
458459 const textFileData = await fs . readFile ( path . join ( __dirname , 'templates/de/custom_email.txt' ) ) ;
@@ -472,7 +473,7 @@ describe('ApiMailAdapter', () => {
472473 return ! / \/ t e m p l a t e s \/ d e ( - A T ) ? \/ / . test ( path ) ;
473474 } ) ;
474475 const _loadFile = spyOn ( adapter , '_loadFile' ) . and . callThrough ( ) ;
475- await adapter . _createPayload ( options ) ;
476+ await adapter . _createApiData ( options ) ;
476477
477478 const subjectFileData = await fs . readFile ( path . join ( __dirname , 'templates/custom_email_subject.txt' ) ) ;
478479 const textFileData = await fs . readFile ( path . join ( __dirname , 'templates/custom_email.txt' ) ) ;
@@ -485,5 +486,16 @@ describe('ApiMailAdapter', () => {
485486 expect ( textSpyData . toString ( 'utf8' ) ) . toEqual ( textFileData . toString ( 'utf8' ) ) ;
486487 expect ( htmlSpyData . toString ( 'utf8' ) ) . toEqual ( htmlFileData . toString ( 'utf8' ) ) ;
487488 } ) ;
489+
490+ it ( 'makes user locale available in API callback' , async ( ) => {
491+ const locale = await options . template . localeCallback ( ) ;
492+ const email = {
493+ templateName : 'customEmailWithLocaleCallback' ,
494+ 495+ direct : true
496+ }
497+ await adapter . _sendMail ( email ) ;
498+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . locale ) . toContain ( locale ) ;
499+ } ) ;
488500 } ) ;
489501} ) ;
0 commit comments