@@ -80,7 +80,7 @@ test('view decorator does not exist if the engine is not provided', async ({ tea
80
80
notOk ( fastify . hasDecorator ( 'view' ) )
81
81
} )
82
82
83
- test ( 'throws an error if point-of-view is not registered' , async ( { teardown, notOk, rejects, ok , equal } ) => {
83
+ test ( 'throws an error if point-of-view is not registered' , async ( { teardown, notOk, rejects } ) => {
84
84
teardown ( ( ) => fastify . close ( ) )
85
85
const fastify = Fastify ( )
86
86
fastify . register ( fastifyMail , { transporter : { jsonTransport : true } } )
@@ -89,7 +89,7 @@ test('throws an error if point-of-view is not registered', async ({ teardown, no
89
89
notOk ( fastify . hasDecorator ( 'view' ) )
90
90
} )
91
91
92
- test ( 'throws an error if an invalid transporter is given' , async ( { teardown, rejects, ok , equal } ) => {
92
+ test ( 'throws an error if an invalid transporter is given' , async ( { teardown, rejects } ) => {
93
93
teardown ( ( ) => fastify . close ( ) )
94
94
const fastify = Fastify ( )
95
95
fastify . register ( fastifyMail , { pov : { engine : { nunjucks } } , transporter : 'error' } )
@@ -145,6 +145,10 @@ test('fastify-mail uses string variables (for text and html) when a template is
145
145
146
146
const fastify = Fastify ( )
147
147
fastify . register ( require ( '@fastify/view' ) , povConfig )
148
+
149
+ const loggedErrors = [ ]
150
+ fastify . log . error = ( msg ) => { loggedErrors . push ( msg ) }
151
+
148
152
fastify . after ( ( ) => {
149
153
fastify . register ( fastifyMail , { pov : { propertyName : 'foo' } , transporter : { jsonTransport : true } } )
150
154
} )
@@ -156,6 +160,7 @@ test('fastify-mail uses string variables (for text and html) when a template is
156
160
157
161
ok ( fastify . hasDecorator ( 'foo' ) )
158
162
same ( sendMailStub . args [ 0 ] , [ testMessage ] )
163
+ equal ( loggedErrors . length , 0 )
159
164
equal ( sendMailStub . args . length , 1 )
160
165
} )
161
166
@@ -178,6 +183,10 @@ test('fastify-mail uses text template when available but defaults to provided ht
178
183
179
184
const fastify = Fastify ( )
180
185
fastify . register ( require ( '@fastify/view' ) , povConfig )
186
+
187
+ const loggedErrors = [ ]
188
+ fastify . log . error = ( msg ) => { loggedErrors . push ( msg ) }
189
+
181
190
fastify . after ( ( ) => {
182
191
fastify . register ( fastifyMail , { pov : { propertyName : 'foo' } , transporter : { jsonTransport : true } } )
183
192
} )
@@ -189,6 +198,7 @@ test('fastify-mail uses text template when available but defaults to provided ht
189
198
190
199
ok ( fastify . hasDecorator ( 'foo' ) )
191
200
same ( sendMailStub . args [ 0 ] [ 0 ] . html , testHtml )
201
+ equal ( loggedErrors . length , 0 )
192
202
equal ( sendMailStub . args . length , 1 )
193
203
} )
194
204
@@ -211,6 +221,10 @@ test('fastify-mail uses html template when available but defaults to provided te
211
221
212
222
const fastify = Fastify ( )
213
223
fastify . register ( require ( '@fastify/view' ) , povConfig )
224
+
225
+ const loggedErrors = [ ]
226
+ fastify . log . error = ( msg ) => { loggedErrors . push ( msg ) }
227
+
214
228
fastify . after ( ( ) => {
215
229
fastify . register ( fastifyMail , { pov : { propertyName : 'foo' } , transporter : { jsonTransport : true } } )
216
230
} )
@@ -223,9 +237,44 @@ test('fastify-mail uses html template when available but defaults to provided te
223
237
ok ( fastify . hasDecorator ( 'foo' ) )
224
238
same ( sendMailStub . args [ 0 ] [ 0 ] . html , testHtml )
225
239
same ( sendMailStub . args [ 0 ] [ 0 ] . text , 'This is a plain text email message.' )
240
+ equal ( loggedErrors . length , 0 )
226
241
equal ( sendMailStub . args . length , 1 )
227
242
} )
228
243
244
+ test ( 'fastify-mail will throw errors if templatePath is defined, but does not exist' , async ( { teardown, testdir, equal } ) => {
245
+ teardown ( ( ) => {
246
+ fastify . close ( )
247
+ sendMailStub . restore ( )
248
+ } )
249
+
250
+ const testTemplates = testdir ( { } )
251
+
252
+ const povConfig = {
253
+ propertyName : 'foo' ,
254
+ engine : { nunjucks } ,
255
+ includeViewExtension : true ,
256
+ options : { filename : resolve ( 'templates' ) }
257
+ }
258
+
259
+ const fastify = Fastify ( )
260
+ fastify . register ( require ( '@fastify/view' ) , povConfig )
261
+
262
+ const loggedErrors = [ ]
263
+ fastify . log . error = ( msg ) => { loggedErrors . push ( msg ) }
264
+
265
+ fastify . after ( ( ) => {
266
+ fastify . register ( fastifyMail , { pov : { propertyName : 'foo' } , transporter : { jsonTransport : true } } )
267
+ } )
268
+ await fastify . ready ( )
269
+
270
+ const sendMailStub = sinon . stub ( fastify . nodemailer , 'sendMail' )
271
+
272
+ await fastify . mail . sendMail ( testMessage , { templatePath : relative ( __dirname , testTemplates ) , context : testContext } )
273
+
274
+ equal ( loggedErrors [ 0 ] , 'fastify-mail: template not found: .tap/fixtures/.-index.test.js-fastify-mail-will-throw-errors-if-templatePath-is-defined-but-does-not-exist/html.njk' )
275
+ equal ( loggedErrors [ 1 ] , 'fastify-mail: template not found: .tap/fixtures/.-index.test.js-fastify-mail-will-throw-errors-if-templatePath-is-defined-but-does-not-exist/text.njk' )
276
+ } )
277
+
229
278
test ( 'fastify.mail.sendMail calls nodemailer.sendMail with correct arguments' , async ( { teardown, testdir, fixture, same, equal } ) => {
230
279
teardown ( ( ) => {
231
280
fastify . close ( )
0 commit comments