@5minds/node-red-contrib-processcube-tools 1.0.1-feature-7fb5cf-mff3dkae → 1.0.1-feature-61e7c9-mff5coiu

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube-tools",
3
- "version": "1.0.1-feature-7fb5cf-mff3dkae",
3
+ "version": "1.0.1-feature-61e7c9-mff5coiu",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED tools nodes for ProcessCube",
6
6
  "scripts": {
@@ -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
- done(); // Success - error status was set
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
- done();
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,7 +228,7 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
222
228
  if (nodeInstance.inputCallback) {
223
229
  nodeInstance.inputCallback({ payload: "test" });
224
230
  } else {
225
- done(new Error('inputCallback was not set on the node instance'));
231
+ completeDone(new Error('inputCallback was not set on the node instance'));
226
232
  }
227
233
  }, 10);
228
234
  });
@@ -234,15 +240,13 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
234
240
  const mockRED = createMockNodeRED({
235
241
  onHandler: function(event, callback) {
236
242
  if (event === 'input') {
237
- // Store the callback on the node instance
238
243
  this.inputCallback = callback;
239
244
  }
240
245
  },
241
246
  statusHandler: function(status) {
242
- if (status.fill === 'green') {
243
- // ASSERT: Should show connected status
244
- status.text.should.containEql('connected');
245
- done();
247
+ // ASSERT: Check for 'connected' status and then complete the test
248
+ if (status.fill === 'green' && status.text === 'connected') {
249
+ done();
246
250
  }
247
251
  }
248
252
  });
@@ -302,36 +306,4 @@ describe('Email Receiver Node - Unit Tests with Helpers', function() {
302
306
  }, 10);
303
307
  });
304
308
  });
305
-
306
- describe('Message Verification Utilities', function() {
307
- it('should verify message properties using testUtils', function() {
308
- // ARRANGE: Create a test message
309
- const testMessage = {
310
- payload: 'test content',
311
- topic: 'email/received',
312
- from: 'test@example.com'
313
- };
314
-
315
- // ACT & ASSERT: Use helper to verify message properties
316
- testUtils.verifyMessage(testMessage, {
317
- payload: 'test content',
318
- topic: 'email/received'
319
- });
320
-
321
- // Should not throw any errors if verification passes
322
- testMessage.should.have.property('from', 'test@example.com');
323
- });
324
-
325
- it('should use wait utility for async operations', async function() {
326
- // ARRANGE: Record start time
327
- const startTime = Date.now();
328
-
329
- // ACT: Use the wait utility
330
- await testUtils.wait(100);
331
-
332
- // ASSERT: Should have waited approximately the right amount of time
333
- const elapsed = Date.now() - startTime;
334
- elapsed.should.be.approximately(100, 50); // Allow 50ms tolerance
335
- });
336
- });
337
309
  });