@@ -123,7 +123,7 @@ describe('ApiMailAdapter', () => {
123123 }
124124 } ) ;
125125
126- it ( 'fails with invalid placeholder callback configuration ' , async ( ) => {
126+ it ( 'fails with invalid placeholder callback' , async ( ) => {
127127 const configs = [
128128 { apiCallback : df , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds , placeholderCallback : { } } } } ,
129129 { apiCallback : df , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds , placeholderCallback : ds } } }
@@ -133,6 +133,29 @@ describe('ApiMailAdapter', () => {
133133 }
134134 } ) ;
135135
136+ it ( 'fails with missing or invalid API callback' , async ( ) => {
137+ const configs = [
138+ { sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds } } } ,
139+ { apiCallback : null , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds } } } ,
140+ { apiCallback : true , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds } } } ,
141+ { apiCallback : ds , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds } } } ,
142+ ] ;
143+ for ( const config of configs ) {
144+ expect ( adapter ( config ) ) . toThrow ( Errors . Error . apiCallbackNoFunction ) ;
145+ }
146+ } ) ;
147+
148+ it ( 'fails with invalid locale callback' , async ( ) => {
149+ const configs = [
150+ { apiCallback : df , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds , localeCallback : ds } } } ,
151+ { apiCallback : df , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds , localeCallback : true } } } ,
152+ { apiCallback : df , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds , localeCallback : [ ] } } } ,
153+ ] ;
154+ for ( const config of configs ) {
155+ expect ( adapter ( config ) ) . toThrow ( Errors . Error . localeCallbackNoFunction ) ;
156+ }
157+ } ) ;
158+
136159 it ( 'succeeds with valid configuration' , async ( ) => {
137160 const configs = [
138161 { apiCallback : df , sender : ds , templates : { customEmail : { subjectPath : ds , textPath : ds } } } ,
@@ -607,7 +630,7 @@ describe('ApiMailAdapter', () => {
607630 expect ( htmlSpyData . toString ( 'utf8' ) ) . toEqual ( htmlFileData . toString ( 'utf8' ) ) ;
608631 } ) ;
609632
610- it ( 'falls back to default file if there is no language or locale match' , async function ( ) {
633+ it ( 'falls back to default file if there is no language or locale match' , async ( ) => {
611634 // Pretend that there are no files in folders `de-AT` and `de`
612635 spyOn ( adapter , '_fileExists' ) . and . callFake ( async ( path ) => {
613636 return ! / \/ t e m p l a t e s \/ d e ( - A T ) ? \/ / . test ( path ) ;
@@ -627,6 +650,16 @@ describe('ApiMailAdapter', () => {
627650 expect ( htmlSpyData . toString ( 'utf8' ) ) . toEqual ( htmlFileData . toString ( 'utf8' ) ) ;
628651 } ) ;
629652
653+ it ( 'falls back to default file if file access throws' , async ( ) => {
654+ const getLocalizedFilePathSpy = spyOn ( adapter , '_getLocalizedFilePath' ) . and . callThrough ( ) ;
655+ spyOn ( fs , 'access' ) . and . callFake ( async ( ) => {
656+ throw 'Test file access error' ;
657+ } ) ;
658+ await adapter . _createApiData ( options ) ;
659+ const file = await getLocalizedFilePathSpy . calls . all ( ) [ 0 ] . returnValue ;
660+ expect ( file ) . toMatch ( options . template . subjectPath ) ;
661+ } ) ;
662+
630663 it ( 'makes user locale available in API callback' , async ( ) => {
631664 const locale = await options . template . localeCallback ( ) ;
632665 const email = {
0 commit comments