@5minds/node-red-contrib-processcube-tools 1.0.1-feature-cf0d8b-mfl5sxpl → 1.0.1-feature-00f482-mfm5528x
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -93,7 +93,7 @@ function createMockNodemailer(options = {}) {
|
|
|
93
93
|
shouldFail: false,
|
|
94
94
|
// New options for different email statuses
|
|
95
95
|
rejectedEmails: [], // Array of emails to mark as rejected
|
|
96
|
-
pendingEmails: [],
|
|
96
|
+
pendingEmails: [], // Array of emails to mark as pending
|
|
97
97
|
acceptedEmails: [], // Array of emails to mark as accepted (overrides default)
|
|
98
98
|
},
|
|
99
99
|
options,
|
|
@@ -118,7 +118,11 @@ function createMockNodemailer(options = {}) {
|
|
|
118
118
|
let rejected = [];
|
|
119
119
|
let pending = [];
|
|
120
120
|
|
|
121
|
-
if (
|
|
121
|
+
if (
|
|
122
|
+
settings.rejectedEmails.length > 0 ||
|
|
123
|
+
settings.pendingEmails.length > 0 ||
|
|
124
|
+
settings.acceptedEmails.length > 0
|
|
125
|
+
) {
|
|
122
126
|
// Use explicit configuration
|
|
123
127
|
if (settings.rejectedEmails.includes(toEmail)) {
|
|
124
128
|
rejected = [toEmail];
|
|
@@ -100,7 +100,7 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
100
100
|
it('should send email successfully and set status to "sent"', function (done) {
|
|
101
101
|
let statusSet = false;
|
|
102
102
|
|
|
103
|
-
// ARRANGE:
|
|
103
|
+
// ARRANGE: Initialize mockNodemailer
|
|
104
104
|
const mockNodemailer = createMockNodemailer();
|
|
105
105
|
|
|
106
106
|
// Mock the nodemailer module
|
|
@@ -147,16 +147,13 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
147
147
|
let redStatusSet = false;
|
|
148
148
|
|
|
149
149
|
function checkDone() {
|
|
150
|
-
console.log('Check done - Error:', errorHandlerCalled, 'Status:', redStatusSet);
|
|
151
150
|
if (errorHandlerCalled && redStatusSet) {
|
|
152
151
|
done();
|
|
153
152
|
}
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
//
|
|
155
|
+
// Explicitly set shouldFail to true
|
|
157
156
|
const mockOptions = { shouldFail: true };
|
|
158
|
-
console.log('Creating mock with options:', mockOptions); // Debug log
|
|
159
|
-
|
|
160
157
|
const mockNodemailer = createMockNodemailer(mockOptions);
|
|
161
158
|
|
|
162
159
|
// Mock the nodemailer module
|
|
@@ -172,14 +169,12 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
172
169
|
}
|
|
173
170
|
},
|
|
174
171
|
statusHandler: function (status) {
|
|
175
|
-
console.log('Status received:', status);
|
|
176
172
|
if (status.fill === 'red' && status.text === 'error sending') {
|
|
177
173
|
redStatusSet = true;
|
|
178
174
|
checkDone();
|
|
179
175
|
}
|
|
180
176
|
},
|
|
181
177
|
errorHandler: function (err) {
|
|
182
|
-
console.log('Error received:', err);
|
|
183
178
|
expect(err.message).to.equal('Mock sendMail error');
|
|
184
179
|
errorHandlerCalled = true;
|
|
185
180
|
checkDone();
|
|
@@ -203,9 +198,7 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
203
198
|
let statusSet = false;
|
|
204
199
|
|
|
205
200
|
function checkDone() {
|
|
206
|
-
console.log('checkDone called - attachmentsChecked:', attachmentsChecked, 'statusSet:', statusSet);
|
|
207
201
|
if (attachmentsChecked && statusSet) {
|
|
208
|
-
console.log('Both conditions met, calling done');
|
|
209
202
|
done();
|
|
210
203
|
}
|
|
211
204
|
}
|
|
@@ -221,54 +214,44 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
221
214
|
content: 'This is the second test file.',
|
|
222
215
|
},
|
|
223
216
|
];
|
|
224
|
-
console.log('Test attachments configured');
|
|
225
217
|
|
|
226
218
|
const mockNodemailer = createMockNodemailer({
|
|
227
219
|
onSendMail: (mailOptions) => {
|
|
228
|
-
console.log('onSendMail called with attachments:', mailOptions.attachments);
|
|
229
220
|
expect(mailOptions.attachments).to.be.an('array').with.lengthOf(2);
|
|
230
221
|
expect(mailOptions.attachments[0].filename).to.equal('test1.txt');
|
|
231
222
|
expect(mailOptions.attachments[1].content).to.equal('This is the second test file.');
|
|
232
223
|
attachmentsChecked = true;
|
|
233
|
-
console.log('Attachments checked successfully');
|
|
234
224
|
checkDone();
|
|
235
225
|
},
|
|
236
226
|
});
|
|
237
|
-
console.log('Mock nodemailer created');
|
|
238
227
|
|
|
239
228
|
// Mock the nodemailer module
|
|
240
229
|
delete require.cache[require.resolve('nodemailer')];
|
|
241
230
|
require.cache[require.resolve('nodemailer')] = {
|
|
242
231
|
exports: mockNodemailer,
|
|
243
232
|
};
|
|
244
|
-
console.log('Nodemailer mock installed');
|
|
245
233
|
|
|
246
234
|
const mockRED = createMockNodeRED({
|
|
247
235
|
onHandler: function (event, callback) {
|
|
248
|
-
console.log('onHandler called with event:', event);
|
|
249
236
|
if (event === 'input') {
|
|
250
237
|
this.inputCallback = callback;
|
|
251
238
|
}
|
|
252
239
|
},
|
|
253
240
|
statusHandler: function (status) {
|
|
254
|
-
console.log('statusHandler called with status:', status);
|
|
255
241
|
if (status.fill === 'green') {
|
|
256
242
|
expect(status.text).to.include('sent');
|
|
257
243
|
expect(status.shape).to.equal('dot');
|
|
258
244
|
statusSet = true;
|
|
259
|
-
console.log('Status set successfully');
|
|
260
245
|
checkDone();
|
|
261
246
|
}
|
|
262
247
|
},
|
|
263
248
|
errorHandler: function (err) {
|
|
264
|
-
console.log('errorHandler called with:', err);
|
|
265
249
|
done(err || new Error('Unexpected error handler called'));
|
|
266
250
|
},
|
|
267
251
|
});
|
|
268
252
|
|
|
269
253
|
const emailSenderNode = require('../../email-sender/email-sender.js');
|
|
270
254
|
emailSenderNode(mockRED);
|
|
271
|
-
console.log('Email sender node initialized');
|
|
272
255
|
|
|
273
256
|
const config = { ...emailSenderConfigs.valid };
|
|
274
257
|
config.attachments = JSON.stringify(attachments);
|
|
@@ -276,7 +259,6 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
276
259
|
|
|
277
260
|
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
278
261
|
const nodeInstance = new nodeConstructor(config);
|
|
279
|
-
console.log('Node instance created');
|
|
280
262
|
|
|
281
263
|
setTimeout(() => {
|
|
282
264
|
nodeInstance.inputCallback({
|
|
@@ -291,7 +273,6 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
291
273
|
let redStatusSet = false;
|
|
292
274
|
|
|
293
275
|
function checkDone() {
|
|
294
|
-
console.log('Check done - Error:', errorHandlerCalled, 'Status:', redStatusSet);
|
|
295
276
|
if (errorHandlerCalled && redStatusSet) {
|
|
296
277
|
done();
|
|
297
278
|
}
|
|
@@ -330,7 +311,6 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
330
311
|
}
|
|
331
312
|
},
|
|
332
313
|
errorHandler: function (err) {
|
|
333
|
-
console.log('Error received:', err);
|
|
334
314
|
expect(err).to.equal("Attachment object is missing 'filename' or 'content' property.");
|
|
335
315
|
errorHandlerCalled = true;
|
|
336
316
|
checkDone();
|
|
@@ -352,25 +332,239 @@ describe('E-Mail Sender Node Unit Tests', function () {
|
|
|
352
332
|
topic: 'test message',
|
|
353
333
|
});
|
|
354
334
|
});
|
|
355
|
-
});
|
|
356
335
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
});
|
|
336
|
+
it('should handle rejected emails and set status to rejected', function (done) {
|
|
337
|
+
let errorHandlerCalled = false;
|
|
338
|
+
let redStatusSet = false;
|
|
361
339
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
340
|
+
function checkDone() {
|
|
341
|
+
if (errorHandlerCalled && redStatusSet) {
|
|
342
|
+
done();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
366
345
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
346
|
+
// ARRANGE: Configure mock to simulate rejected emails
|
|
347
|
+
const mockOptions = {
|
|
348
|
+
rejectedEmails: ['recipient@example.com'],
|
|
349
|
+
acceptedEmails: [], // Ensure no emails are accepted
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const mockNodemailer = createMockNodemailer(mockOptions);
|
|
353
|
+
|
|
354
|
+
// Mock the nodemailer module
|
|
355
|
+
delete require.cache[require.resolve('nodemailer')];
|
|
356
|
+
require.cache[require.resolve('nodemailer')] = {
|
|
357
|
+
exports: mockNodemailer,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const mockRED = createMockNodeRED({
|
|
361
|
+
onHandler: function (event, callback) {
|
|
362
|
+
if (event === 'input') {
|
|
363
|
+
this.inputCallback = callback;
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
statusHandler: function (status) {
|
|
367
|
+
if (status.fill === 'red' && status.text === 'rejected') {
|
|
368
|
+
redStatusSet = true;
|
|
369
|
+
checkDone();
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
errorHandler: function (err) {
|
|
373
|
+
expect(err.message).to.include('Email rejected: recipient@example.com');
|
|
374
|
+
errorHandlerCalled = true;
|
|
375
|
+
checkDone();
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const emailSenderNode = require('../../email-sender/email-sender.js');
|
|
380
|
+
emailSenderNode(mockRED);
|
|
381
|
+
|
|
382
|
+
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
383
|
+
const nodeInstance = new nodeConstructor(emailSenderConfigs.valid);
|
|
384
|
+
|
|
385
|
+
nodeInstance.inputCallback({
|
|
386
|
+
payload: 'test',
|
|
387
|
+
topic: 'test message',
|
|
388
|
+
});
|
|
389
|
+
});
|
|
371
390
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
391
|
+
it('should handle pending emails and set status to pending', function (done) {
|
|
392
|
+
let errorHandlerCalled = false;
|
|
393
|
+
let yellowStatusSet = false;
|
|
394
|
+
|
|
395
|
+
function checkDone() {
|
|
396
|
+
if (errorHandlerCalled && yellowStatusSet) {
|
|
397
|
+
done();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// ARRANGE: Configure mock to simulate pending emails
|
|
402
|
+
const mockOptions = {
|
|
403
|
+
pendingEmails: ['recipient@example.com'],
|
|
404
|
+
acceptedEmails: [], // Ensure no emails are accepted
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const mockNodemailer = createMockNodemailer(mockOptions);
|
|
408
|
+
|
|
409
|
+
// Mock the nodemailer module
|
|
410
|
+
delete require.cache[require.resolve('nodemailer')];
|
|
411
|
+
require.cache[require.resolve('nodemailer')] = {
|
|
412
|
+
exports: mockNodemailer,
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
const mockRED = createMockNodeRED({
|
|
416
|
+
onHandler: function (event, callback) {
|
|
417
|
+
if (event === 'input') {
|
|
418
|
+
this.inputCallback = callback;
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
statusHandler: function (status) {
|
|
422
|
+
if (status.fill === 'yellow' && status.text === 'pending') {
|
|
423
|
+
yellowStatusSet = true;
|
|
424
|
+
checkDone();
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
errorHandler: function (err) {
|
|
428
|
+
expect(err.message).to.include('Email pending: recipient@example.com');
|
|
429
|
+
errorHandlerCalled = true;
|
|
430
|
+
checkDone();
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
const emailSenderNode = require('../../email-sender/email-sender.js');
|
|
435
|
+
emailSenderNode(mockRED);
|
|
436
|
+
|
|
437
|
+
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
438
|
+
const nodeInstance = new nodeConstructor(emailSenderConfigs.valid);
|
|
439
|
+
|
|
440
|
+
nodeInstance.inputCallback({
|
|
441
|
+
payload: 'test',
|
|
442
|
+
topic: 'test message',
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('should handle a single attachment object correctly', function (done) {
|
|
447
|
+
let attachmentChecked = false;
|
|
448
|
+
let statusSet = false;
|
|
449
|
+
|
|
450
|
+
function checkDone() {
|
|
451
|
+
if (attachmentChecked && statusSet) {
|
|
452
|
+
done();
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// ARRANGE: Configure test with single attachment object
|
|
457
|
+
const singleAttachment = {
|
|
458
|
+
filename: 'single-test.txt',
|
|
459
|
+
content: 'This is a single test file.',
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
const mockNodemailer = createMockNodemailer({
|
|
463
|
+
onSendMail: (mailOptions) => {
|
|
464
|
+
expect(mailOptions.attachments).to.be.an('array').with.lengthOf(1);
|
|
465
|
+
expect(mailOptions.attachments[0].filename).to.equal('single-test.txt');
|
|
466
|
+
expect(mailOptions.attachments[0].content).to.equal('This is a single test file.');
|
|
467
|
+
attachmentChecked = true;
|
|
468
|
+
checkDone();
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
// Mock the nodemailer module
|
|
473
|
+
delete require.cache[require.resolve('nodemailer')];
|
|
474
|
+
require.cache[require.resolve('nodemailer')] = {
|
|
475
|
+
exports: mockNodemailer,
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
const mockRED = createMockNodeRED({
|
|
479
|
+
onHandler: function (event, callback) {
|
|
480
|
+
if (event === 'input') {
|
|
481
|
+
this.inputCallback = callback;
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
statusHandler: function (status) {
|
|
485
|
+
if (status.fill === 'green') {
|
|
486
|
+
expect(status.text).to.include('sent');
|
|
487
|
+
expect(status.shape).to.equal('dot');
|
|
488
|
+
statusSet = true;
|
|
489
|
+
checkDone();
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
errorHandler: function (err) {
|
|
493
|
+
done(err || new Error('Unexpected error handler called'));
|
|
494
|
+
},
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
const emailSenderNode = require('../../email-sender/email-sender.js');
|
|
498
|
+
emailSenderNode(mockRED);
|
|
499
|
+
|
|
500
|
+
const config = { ...emailSenderConfigs.valid };
|
|
501
|
+
config.attachments = JSON.stringify(singleAttachment);
|
|
502
|
+
config.attachmentsType = 'json';
|
|
503
|
+
|
|
504
|
+
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
505
|
+
const nodeInstance = new nodeConstructor(config);
|
|
506
|
+
|
|
507
|
+
setTimeout(() => {
|
|
508
|
+
nodeInstance.inputCallback({
|
|
509
|
+
payload: 'test',
|
|
510
|
+
topic: 'test message',
|
|
511
|
+
});
|
|
512
|
+
}, 100);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it('should handle an empty attachments string without error', function (done) {
|
|
516
|
+
let statusSet = false;
|
|
517
|
+
|
|
518
|
+
// ARRANGE: Create mock nodemailer to verify no attachments are processed
|
|
519
|
+
const mockNodemailer = createMockNodemailer({
|
|
520
|
+
onSendMail: (mailOptions) => {
|
|
521
|
+
// Should be an empty array when no attachments are provided
|
|
522
|
+
expect(mailOptions.attachments).to.be.an('array').with.lengthOf(0);
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// Mock the nodemailer module
|
|
527
|
+
delete require.cache[require.resolve('nodemailer')];
|
|
528
|
+
require.cache[require.resolve('nodemailer')] = {
|
|
529
|
+
exports: mockNodemailer,
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
const mockRED = createMockNodeRED({
|
|
533
|
+
onHandler: function (event, callback) {
|
|
534
|
+
if (event === 'input') {
|
|
535
|
+
this.inputCallback = callback;
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
statusHandler: function (status) {
|
|
539
|
+
if (status.fill === 'green') {
|
|
540
|
+
expect(status.text).to.include('sent');
|
|
541
|
+
expect(status.shape).to.equal('dot');
|
|
542
|
+
statusSet = true;
|
|
543
|
+
done();
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
errorHandler: function (err) {
|
|
547
|
+
done(err || new Error('Unexpected error handler called'));
|
|
548
|
+
},
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
const emailSenderNode = require('../../email-sender/email-sender.js');
|
|
552
|
+
emailSenderNode(mockRED);
|
|
553
|
+
|
|
554
|
+
const config = { ...emailSenderConfigs.valid };
|
|
555
|
+
// Set attachments to empty string to test this scenario
|
|
556
|
+
config.attachments = '';
|
|
557
|
+
config.attachmentsType = 'str';
|
|
558
|
+
|
|
559
|
+
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
560
|
+
const nodeInstance = new nodeConstructor(config);
|
|
561
|
+
|
|
562
|
+
setTimeout(() => {
|
|
563
|
+
nodeInstance.inputCallback({
|
|
564
|
+
payload: 'test',
|
|
565
|
+
topic: 'test message',
|
|
566
|
+
});
|
|
567
|
+
}, 100);
|
|
568
|
+
});
|
|
375
569
|
});
|
|
376
570
|
});
|