@5minds/node-red-contrib-processcube-tools 1.0.1-feature-20a8ee-mff2npts → 1.0.1-feature-7fb5cf-mff3dkae
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
|
|
|
@@ -228,56 +228,16 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
228
228
|
});
|
|
229
229
|
});
|
|
230
230
|
|
|
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
231
|
describe('IMAP Connection', function() {
|
|
278
232
|
it('should handle connection success', function(done) {
|
|
279
233
|
// ARRANGE: Set up connection tracking
|
|
280
234
|
const mockRED = createMockNodeRED({
|
|
235
|
+
onHandler: function(event, callback) {
|
|
236
|
+
if (event === 'input') {
|
|
237
|
+
// Store the callback on the node instance
|
|
238
|
+
this.inputCallback = callback;
|
|
239
|
+
}
|
|
240
|
+
},
|
|
281
241
|
statusHandler: function(status) {
|
|
282
242
|
if (status.fill === 'green') {
|
|
283
243
|
// ASSERT: Should show connected status
|
|
@@ -287,15 +247,30 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
287
247
|
}
|
|
288
248
|
});
|
|
289
249
|
|
|
290
|
-
// ACT: Create node
|
|
250
|
+
// ACT: Create node with config that should fail
|
|
291
251
|
emailReceiverNode(mockRED);
|
|
292
252
|
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
293
|
-
new nodeConstructor(testConfigs.valid);
|
|
253
|
+
const nodeInstance = new nodeConstructor(testConfigs.valid);
|
|
254
|
+
|
|
255
|
+
// Trigger the connection attempt by sending an input message
|
|
256
|
+
setTimeout(() => {
|
|
257
|
+
if (nodeInstance.inputCallback) {
|
|
258
|
+
nodeInstance.inputCallback({ payload: "test" });
|
|
259
|
+
} else {
|
|
260
|
+
done(new Error('inputCallback was not set on the node instance'));
|
|
261
|
+
}
|
|
262
|
+
}, 10);
|
|
294
263
|
});
|
|
295
264
|
|
|
296
265
|
it('should handle connection errors', function(done) {
|
|
297
266
|
// ARRANGE: Set up error tracking
|
|
298
267
|
const mockRED = createMockNodeRED({
|
|
268
|
+
onHandler: function(event, callback) {
|
|
269
|
+
if (event === 'input') {
|
|
270
|
+
// Store the callback on the node instance
|
|
271
|
+
this.inputCallback = callback;
|
|
272
|
+
}
|
|
273
|
+
},
|
|
299
274
|
errorHandler: function(err) {
|
|
300
275
|
// ASSERT: Should handle connection errors gracefully
|
|
301
276
|
should.exist(err);
|
|
@@ -315,7 +290,16 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
|
315
290
|
|
|
316
291
|
// Use invalid config to trigger connection error
|
|
317
292
|
const invalidConfig = { ...testConfigs.valid, host: 'invalid.host.com' };
|
|
318
|
-
new nodeConstructor(invalidConfig);
|
|
293
|
+
const nodeInstance = new nodeConstructor(invalidConfig);
|
|
294
|
+
|
|
295
|
+
// Trigger the connection attempt by sending an input message
|
|
296
|
+
setTimeout(() => {
|
|
297
|
+
if (nodeInstance.inputCallback) {
|
|
298
|
+
nodeInstance.inputCallback({ payload: "test" });
|
|
299
|
+
} else {
|
|
300
|
+
done(new Error('inputCallback was not set on the node instance'));
|
|
301
|
+
}
|
|
302
|
+
}, 10);
|
|
319
303
|
});
|
|
320
304
|
});
|
|
321
305
|
|