@5minds/node-red-contrib-processcube-tools 1.0.1-feature-e7a81a-mfdq8poq → 1.0.1-feature-d1ae95-mfds5a5x
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.
|
@@ -19,10 +19,8 @@ module.exports = function(RED) {
|
|
|
19
19
|
let folders;
|
|
20
20
|
if (Array.isArray(imap_folder)) {
|
|
21
21
|
folders = imap_folder;
|
|
22
|
-
} else if (typeof imap_folder === 'string') {
|
|
23
|
-
folders = imap_folder.split(',').map(f => f.trim()).filter(f => f.length > 0);
|
|
24
22
|
} else {
|
|
25
|
-
const errorMsg = "The 'folders' property must be an array of strings
|
|
23
|
+
const errorMsg = "The 'folders' property must be an array of strings.";
|
|
26
24
|
node.status({ fill: 'red', shape: 'ring', text: errorMsg });
|
|
27
25
|
node.error(errorMsg, msg);
|
|
28
26
|
return;
|
|
@@ -45,7 +43,14 @@ module.exports = function(RED) {
|
|
|
45
43
|
};
|
|
46
44
|
|
|
47
45
|
if (!finalConfig.user || !finalConfig.password || !finalConfig.port || !finalConfig.host || !finalConfig.folders) {
|
|
48
|
-
const
|
|
46
|
+
const missingFields = [];
|
|
47
|
+
if (!finalConfig.user) missingFields.push('user');
|
|
48
|
+
if (!finalConfig.password) missingFields.push('password');
|
|
49
|
+
if (!finalConfig.port) missingFields.push('port');
|
|
50
|
+
if (!finalConfig.host) missingFields.push('host');
|
|
51
|
+
if (!finalConfig.folders) missingFields.push('folders');
|
|
52
|
+
|
|
53
|
+
const errorMessage = `Missing required IMAP config: ${missingFields.join(', ')}. Aborting.`;
|
|
49
54
|
node.status({ fill: 'red', shape: 'ring', text: 'missing config' });
|
|
50
55
|
node.error(errorMessage);
|
|
51
56
|
return;
|
package/package.json
CHANGED
|
@@ -168,8 +168,8 @@ describe('Email Receiver Node - Unit Tests', function() {
|
|
|
168
168
|
userType: 'str',
|
|
169
169
|
password: 'testpass',
|
|
170
170
|
passwordType: 'str',
|
|
171
|
-
folder:
|
|
172
|
-
folderType: '
|
|
171
|
+
folder: ["INBOX"],
|
|
172
|
+
folderType: 'json',
|
|
173
173
|
markseen: true,
|
|
174
174
|
markseenType: 'bool'
|
|
175
175
|
};
|
|
@@ -201,6 +201,9 @@ describe('Email Receiver Node - Unit Tests', function() {
|
|
|
201
201
|
// ARRANGE: Mock the Node-RED environment
|
|
202
202
|
let nodeInstance;
|
|
203
203
|
let inputCallback;
|
|
204
|
+
let messagesSent = 0;
|
|
205
|
+
const expectedMessages = 2;
|
|
206
|
+
|
|
204
207
|
const mockRED = {
|
|
205
208
|
nodes: {
|
|
206
209
|
createNode: function(node, config) {
|
|
@@ -211,29 +214,58 @@ describe('Email Receiver Node - Unit Tests', function() {
|
|
|
211
214
|
node.send = (msg) => {
|
|
212
215
|
should.exist(msg);
|
|
213
216
|
msg.payload.should.equal('test body');
|
|
214
|
-
|
|
217
|
+
messagesSent++;
|
|
218
|
+
if (messagesSent === expectedMessages) {
|
|
219
|
+
done();
|
|
220
|
+
}
|
|
215
221
|
};
|
|
216
222
|
return node;
|
|
217
223
|
},
|
|
218
224
|
registerType: (type, constructor) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
const mockNode = {
|
|
226
|
+
id: 'mock-node-id',
|
|
227
|
+
on: (event, callback) => {
|
|
228
|
+
if (event === 'input') {
|
|
229
|
+
inputCallback = callback;
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
status: () => {},
|
|
233
|
+
error: () => {},
|
|
234
|
+
send: (msg) => {
|
|
235
|
+
should.exist(msg);
|
|
236
|
+
msg.payload.should.equal('test body');
|
|
237
|
+
messagesSent++;
|
|
238
|
+
if (messagesSent === expectedMessages) {
|
|
239
|
+
done();
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
// Create an instance of the node with the test configuration
|
|
244
|
+
const node = new constructor(mockNode, {
|
|
245
|
+
host: "imap.test.com", hostType: "str",
|
|
246
|
+
port: 993, portType: "num",
|
|
247
|
+
user: "test@test.com", userType: "str",
|
|
248
|
+
password: "testpass", passwordType: "str",
|
|
249
|
+
folder: ["INBOX", "Junk"], folderType: 'json',
|
|
250
|
+
markseen: true, markseenType: 'bool'
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
util: { evaluateNodeProperty: (value) => value },
|
|
255
|
+
};
|
|
231
256
|
|
|
232
257
|
// ACT: Register the node, then simulate input
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
258
|
+
emailReceiverNode(mockRED);
|
|
259
|
+
// After the node is registered, simulate an input to trigger the flow
|
|
260
|
+
setTimeout(() => {
|
|
261
|
+
if (inputCallback) {
|
|
262
|
+
inputCallback({});
|
|
263
|
+
} else {
|
|
264
|
+
done(new Error("Input callback not set up."));
|
|
265
|
+
}
|
|
266
|
+
}, 50); // Use a small timeout to ensure the mocks are fully set up
|
|
236
267
|
});
|
|
268
|
+
});
|
|
237
269
|
|
|
238
270
|
describe('Error Handling', function() {
|
|
239
271
|
it('should call node.error for invalid folder type', function(done) {
|
|
@@ -273,7 +305,7 @@ describe('Email Receiver Node - Unit Tests', function() {
|
|
|
273
305
|
port: 993, portType: "num",
|
|
274
306
|
user: "test@test.com", userType: "str",
|
|
275
307
|
password: "", passwordType: "str", // Empty password should trigger error
|
|
276
|
-
folder: "INBOX", folderType: "
|
|
308
|
+
folder: ["INBOX"], folderType: "json"
|
|
277
309
|
},
|
|
278
310
|
on: (event, callback) => { if (event === 'input') nodeInstance.inputCallback = callback; },
|
|
279
311
|
status: (s) => { statusCalled = true; s.fill.should.equal('red'); },
|