@@ -38,9 +38,12 @@ const config = {
3838 subjectPath : path . join ( __dirname , 'templates/custom_email_subject.txt' ) ,
3939 textPath : path . join ( __dirname , 'templates/custom_email.txt' ) ,
4040 htmlPath : path . join ( __dirname , 'templates/custom_email.html' ) ,
41+ placeholders : {
42+ appName : "TemplatePlaceholder"
43+ } ,
4144 placeholderCallback : ( ) => new Promise ( ( resolve ) => {
4245 resolve ( {
43- appName : 'ExampleApp '
46+ appName : 'CallbackPlaceholder '
4447 } ) ;
4548 } )
4649 } ,
@@ -49,7 +52,21 @@ const config = {
4952 textPath : path . join ( __dirname , 'templates/custom_email.txt' ) ,
5053 htmlPath : path . join ( __dirname , 'templates/custom_email.html' ) ,
5154 localeCallback : async ( ) => { return 'de-AT' ; }
52- }
55+ } ,
56+ customEmailWithPlaceholderCallbackAndLocaleCallback : {
57+ subjectPath : path . join ( __dirname , 'templates/custom_email_subject.txt' ) ,
58+ textPath : path . join ( __dirname , 'templates/custom_email.txt' ) ,
59+ htmlPath : path . join ( __dirname , 'templates/custom_email.html' ) ,
60+ placeholders : {
61+ appName : "TemplatePlaceholder"
62+ } ,
63+ placeholderCallback : ( ) => new Promise ( ( resolve ) => {
64+ resolve ( {
65+ appName : 'CallbackPlaceholder'
66+ } ) ;
67+ } ) ,
68+ localeCallback : async ( ) => { return 'de-AT' ; }
69+ } ,
5370 }
5471} ;
5572const examplePayload = {
@@ -448,6 +465,21 @@ describe('ApiMailAdapter', () => {
448465 expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . text ) . toContain ( callbackPlaceholder ) ;
449466 expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . payload . text ) . not . toContain ( templatePlaceholder ) ;
450467 } ) ;
468+
469+ it ( 'makes user locale accessible in placeholder callback' , async ( ) => {
470+ const adapter = new ApiMailAdapter ( config ) ;
471+ const apiCallback = spyOn ( adapter , 'apiCallback' ) . and . callThrough ( ) ;
472+ const email = {
473+ templateName : 'customEmailWithPlaceholderCallbackAndLocaleCallback' ,
474+ 475+ direct : true
476+ }
477+ const template = config . templates [ email . templateName ] ;
478+ const locale = await template . localeCallback ( ) ;
479+
480+ await adapter . _sendMail ( email ) ;
481+ expect ( apiCallback . calls . all ( ) [ 0 ] . args [ 0 ] . locale ) . toBe ( locale ) ;
482+ } ) ;
451483 } ) ;
452484
453485 describe ( 'localization' , ( ) => {
0 commit comments