@5minds/node-red-contrib-processcube-tools 1.0.1-feature-20a8ee-mff2npts → 1.0.1-feature-7ab4ae-mff3roeh
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
|
@@ -12,10 +12,21 @@ function createMockImap() {
|
|
|
12
12
|
|
|
13
13
|
// Simulate connection behavior
|
|
14
14
|
this.connect = () => {
|
|
15
|
-
//
|
|
16
|
-
if (this.
|
|
17
|
-
//
|
|
18
|
-
|
|
15
|
+
// Check if we should simulate a connection error
|
|
16
|
+
if (this.config.host && this.config.host.includes('invalid')) {
|
|
17
|
+
// Simulate connection error
|
|
18
|
+
if (this.events && this.events.error) {
|
|
19
|
+
setTimeout(() => {
|
|
20
|
+
const error = new Error('Connection failed');
|
|
21
|
+
error.code = 'ENOTFOUND';
|
|
22
|
+
this.events.error(error);
|
|
23
|
+
}, 10);
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
// Simulate successful connection by emitting 'ready' event
|
|
27
|
+
if (this.events && this.events.ready) {
|
|
28
|
+
setTimeout(() => this.events.ready(), 10);
|
|
29
|
+
}
|
|
19
30
|
}
|
|
20
31
|
};
|
|
21
32
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
const should = require('should');
|
|
2
2
|
const {
|
|
3
|
-
createMockImap,
|
|
4
|
-
createMockMailparser,
|
|
5
3
|
createMockNodeRED,
|
|
6
4
|
setupModuleMocks,
|
|
7
5
|
testConfigs,
|
|
@@ -184,7 +182,16 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
184
182
|
});
|
|
185
183
|
|
|
186
184
|
it('should handle connection errors gracefully', function(done) {
|
|
187
|
-
// ARRANGE: Set up connection error scenario
|
|
185
|
+
// ARRANGE: Set up connection error scenario with done() protection
|
|
186
|
+
let testCompleted = false;
|
|
187
|
+
|
|
188
|
+
const completeDone = () => {
|
|
189
|
+
if (!testCompleted) {
|
|
190
|
+
testCompleted = true;
|
|
191
|
+
done();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
188
195
|
const mockRED = createMockNodeRED({
|
|
189
196
|
onHandler: function(event, callback) {
|
|
190
197
|
if (event === 'input') {
|
|
@@ -193,20 +200,16 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
193
200
|
},
|
|
194
201
|
statusHandler: function(status) {
|
|
195
202
|
if (status.fill === 'red' && status.text && status.text.includes('error')) {
|
|
196
|
-
|
|
203
|
+
completeDone(); // Success - error status was set
|
|
197
204
|
}
|
|
198
205
|
},
|
|
199
206
|
errorHandler: function(err) {
|
|
200
207
|
// Also accept errors as valid completion
|
|
201
208
|
should.exist(err);
|
|
202
|
-
|
|
209
|
+
completeDone();
|
|
203
210
|
}
|
|
204
211
|
});
|
|
205
212
|
|
|
206
|
-
// ACT: Create node and trigger connection attempt
|
|
207
|
-
emailReceiverNode(mockRED);
|
|
208
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
209
|
-
|
|
210
213
|
// Use a config that should cause connection issues
|
|
211
214
|
const badConfig = {
|
|
212
215
|
...testConfigs.valid,
|
|
@@ -214,6 +217,9 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
214
217
|
port: 12345 // Invalid port
|
|
215
218
|
};
|
|
216
219
|
|
|
220
|
+
// ACT: Register node and create instance with invalid config
|
|
221
|
+
emailReceiverNode(mockRED);
|
|
222
|
+
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
217
223
|
const nodeInstance = new nodeConstructor(badConfig);
|
|
218
224
|
|
|
219
225
|
// Trigger the error by sending an input message
|
|
@@ -222,62 +228,22 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
222
228
|
if (nodeInstance.inputCallback) {
|
|
223
229
|
nodeInstance.inputCallback({ payload: "test" });
|
|
224
230
|
} else {
|
|
225
|
-
|
|
231
|
+
completeDone(new Error('inputCallback was not set on the node instance'));
|
|
226
232
|
}
|
|
227
233
|
}, 10);
|
|
228
234
|
});
|
|
229
235
|
});
|
|
230
236
|
|
|
231
|
-
describe('Message Processing', function() {
|
|
232
|
-
it('should process email message correctly', async function() {
|
|
233
|
-
// ARRANGE: Set up message capture
|
|
234
|
-
let processedMessage = null;
|
|
235
|
-
const mockRED = createMockNodeRED({
|
|
236
|
-
sendHandler: function(msg) {
|
|
237
|
-
processedMessage = msg;
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// ACT: Create node and simulate email processing
|
|
242
|
-
emailReceiverNode(mockRED);
|
|
243
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
244
|
-
const nodeInstance = new nodeConstructor(testConfigs.valid);
|
|
245
|
-
|
|
246
|
-
// Simulate input trigger (this would depend on your node's implementation)
|
|
247
|
-
// The actual trigger mechanism would need to match your node's design
|
|
248
|
-
|
|
249
|
-
await testUtils.wait(100);
|
|
250
|
-
|
|
251
|
-
// ASSERT: Message processing behavior would be verified here
|
|
252
|
-
// The specific assertions depend on your node's output format
|
|
253
|
-
should.exist(nodeInstance);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('should handle multiple messages', async function() {
|
|
257
|
-
// ARRANGE: Set up message collection
|
|
258
|
-
const messages = [];
|
|
259
|
-
const mockRED = createMockNodeRED({
|
|
260
|
-
sendHandler: function(msg) {
|
|
261
|
-
messages.push(msg);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// ACT: Create node and simulate multiple emails
|
|
266
|
-
emailReceiverNode(mockRED);
|
|
267
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
268
|
-
const nodeInstance = new nodeConstructor(testConfigs.valid);
|
|
269
|
-
|
|
270
|
-
await testUtils.wait(150);
|
|
271
|
-
|
|
272
|
-
// ASSERT: Should handle multiple messages appropriately
|
|
273
|
-
should.exist(nodeInstance);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
237
|
describe('IMAP Connection', function() {
|
|
278
238
|
it('should handle connection success', function(done) {
|
|
279
239
|
// ARRANGE: Set up connection tracking
|
|
280
240
|
const mockRED = createMockNodeRED({
|
|
241
|
+
onHandler: function(event, callback) {
|
|
242
|
+
if (event === 'input') {
|
|
243
|
+
// Store the callback on the node instance
|
|
244
|
+
this.inputCallback = callback;
|
|
245
|
+
}
|
|
246
|
+
},
|
|
281
247
|
statusHandler: function(status) {
|
|
282
248
|
if (status.fill === 'green') {
|
|
283
249
|
// ASSERT: Should show connected status
|
|
@@ -287,15 +253,30 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
287
253
|
}
|
|
288
254
|
});
|
|
289
255
|
|
|
290
|
-
// ACT: Create node
|
|
256
|
+
// ACT: Create node with config that should fail
|
|
291
257
|
emailReceiverNode(mockRED);
|
|
292
258
|
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
293
|
-
new nodeConstructor(testConfigs.valid);
|
|
259
|
+
const nodeInstance = new nodeConstructor(testConfigs.valid);
|
|
260
|
+
|
|
261
|
+
// Trigger the connection attempt by sending an input message
|
|
262
|
+
setTimeout(() => {
|
|
263
|
+
if (nodeInstance.inputCallback) {
|
|
264
|
+
nodeInstance.inputCallback({ payload: "test" });
|
|
265
|
+
} else {
|
|
266
|
+
done(new Error('inputCallback was not set on the node instance'));
|
|
267
|
+
}
|
|
268
|
+
}, 10);
|
|
294
269
|
});
|
|
295
270
|
|
|
296
271
|
it('should handle connection errors', function(done) {
|
|
297
272
|
// ARRANGE: Set up error tracking
|
|
298
273
|
const mockRED = createMockNodeRED({
|
|
274
|
+
onHandler: function(event, callback) {
|
|
275
|
+
if (event === 'input') {
|
|
276
|
+
// Store the callback on the node instance
|
|
277
|
+
this.inputCallback = callback;
|
|
278
|
+
}
|
|
279
|
+
},
|
|
299
280
|
errorHandler: function(err) {
|
|
300
281
|
// ASSERT: Should handle connection errors gracefully
|
|
301
282
|
should.exist(err);
|
|
@@ -315,39 +296,16 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
315
296
|
|
|
316
297
|
// Use invalid config to trigger connection error
|
|
317
298
|
const invalidConfig = { ...testConfigs.valid, host: 'invalid.host.com' };
|
|
318
|
-
new nodeConstructor(invalidConfig);
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
describe('Message Verification Utilities', function() {
|
|
323
|
-
it('should verify message properties using testUtils', function() {
|
|
324
|
-
// ARRANGE: Create a test message
|
|
325
|
-
const testMessage = {
|
|
326
|
-
payload: 'test content',
|
|
327
|
-
topic: 'email/received',
|
|
328
|
-
from: 'test@example.com'
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// ACT & ASSERT: Use helper to verify message properties
|
|
332
|
-
testUtils.verifyMessage(testMessage, {
|
|
333
|
-
payload: 'test content',
|
|
334
|
-
topic: 'email/received'
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// Should not throw any errors if verification passes
|
|
338
|
-
testMessage.should.have.property('from', 'test@example.com');
|
|
339
|
-
});
|
|
299
|
+
const nodeInstance = new nodeConstructor(invalidConfig);
|
|
340
300
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const elapsed = Date.now() - startTime;
|
|
350
|
-
elapsed.should.be.approximately(100, 50); // Allow 50ms tolerance
|
|
301
|
+
// Trigger the connection attempt by sending an input message
|
|
302
|
+
setTimeout(() => {
|
|
303
|
+
if (nodeInstance.inputCallback) {
|
|
304
|
+
nodeInstance.inputCallback({ payload: "test" });
|
|
305
|
+
} else {
|
|
306
|
+
done(new Error('inputCallback was not set on the node instance'));
|
|
307
|
+
}
|
|
308
|
+
}, 10);
|
|
351
309
|
});
|
|
352
310
|
});
|
|
353
311
|
});
|