@5minds/node-red-contrib-processcube-tools 1.0.1-feature-e7a81a-mfdq8poq → 1.0.1-feature-4ad612-mfdvfdql
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/email-sender/email-sender.html +50 -0
- package/email-sender/email-sender.js +84 -0
- package/package.json +4 -27
- package/email-receiver/email-receiver.html +0 -187
- package/email-receiver/email-receiver.js +0 -231
- package/test/helpers/email-receiver.mocks.js +0 -379
- package/test/integration/email-receiver.integration.test.js +0 -492
- package/test/unit/email-receiver.unit.test.js +0 -300
- /package/{processcube-html-to-text.html → processcube-html-to-text/processcube-html-to-text.html} +0 -0
- /package/{processcube-html-to-text.js → processcube-html-to-text/processcube-html-to-text.js} +0 -0
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared mock objects and utilities for Email Receiver Node tests
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Mock IMAP implementation for testing
|
|
7
|
-
*/
|
|
8
|
-
function createMockImap() {
|
|
9
|
-
return function MockImap(config) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.events = {};
|
|
12
|
-
|
|
13
|
-
// Simulate connection behavior
|
|
14
|
-
this.connect = () => {
|
|
15
|
-
// Simulate successful connection by emitting 'ready' event
|
|
16
|
-
if (this.events && this.events.ready) {
|
|
17
|
-
// Use setTimeout to simulate async behavior
|
|
18
|
-
setTimeout(() => this.events.ready(), 10);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Simulate opening a mailbox
|
|
23
|
-
this.openBox = (folder, readOnly, callback) => {
|
|
24
|
-
setTimeout(() => {
|
|
25
|
-
callback(null, {
|
|
26
|
-
messages: { total: 1 },
|
|
27
|
-
name: folder,
|
|
28
|
-
readOnly: readOnly
|
|
29
|
-
});
|
|
30
|
-
}, 10);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// Simulate searching for emails
|
|
34
|
-
this.search = (criteria, callback) => {
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
// Return mock message IDs
|
|
37
|
-
callback(null, [123, 456, 789]);
|
|
38
|
-
}, 10);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// Simulate fetching email messages
|
|
42
|
-
this.fetch = (results, options) => {
|
|
43
|
-
return {
|
|
44
|
-
on: (event, callback) => {
|
|
45
|
-
if (event === 'message') {
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
const mockMessage = {
|
|
48
|
-
on: (messageEvent, messageCallback) => {
|
|
49
|
-
if (messageEvent === 'body') {
|
|
50
|
-
setTimeout(() => {
|
|
51
|
-
messageCallback(Buffer.from('mock email body'));
|
|
52
|
-
}, 5);
|
|
53
|
-
} else if (messageEvent === 'attributes') {
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
messageCallback({
|
|
56
|
-
uid: 123,
|
|
57
|
-
flags: ['\\Seen'],
|
|
58
|
-
date: new Date(),
|
|
59
|
-
size: 1024
|
|
60
|
-
});
|
|
61
|
-
}, 5);
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
once: (messageEvent, messageCallback) => {
|
|
65
|
-
if (messageEvent === 'end') {
|
|
66
|
-
setTimeout(() => messageCallback(), 15);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
callback(mockMessage);
|
|
71
|
-
}, 10);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
once: (event, callback) => {
|
|
75
|
-
if (event === 'end') {
|
|
76
|
-
setTimeout(() => callback(), 20);
|
|
77
|
-
} else if (event === 'error') {
|
|
78
|
-
// Store error callback for potential use
|
|
79
|
-
this.errorCallback = callback;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// Simulate closing connection
|
|
86
|
-
this.end = () => {
|
|
87
|
-
if (this.events && this.events.end) {
|
|
88
|
-
setTimeout(() => this.events.end(), 5);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// Event listener setup
|
|
93
|
-
this.once = (event, callback) => {
|
|
94
|
-
if (!this.events) this.events = {};
|
|
95
|
-
this.events[event] = callback;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// Additional IMAP methods that might be used
|
|
99
|
-
this.addFlags = (source, flags, callback) => {
|
|
100
|
-
setTimeout(() => callback(null), 5);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
this.removeFlags = (source, flags, callback) => {
|
|
104
|
-
setTimeout(() => callback(null), 5);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return this;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Mock Mailparser implementation for testing
|
|
113
|
-
*/
|
|
114
|
-
function createMockMailparser() {
|
|
115
|
-
return {
|
|
116
|
-
simpleParser: function(source, options = {}) {
|
|
117
|
-
return Promise.resolve({
|
|
118
|
-
subject: options.subject || 'Mock Email Subject',
|
|
119
|
-
text: options.text || 'This is a mock email body for testing purposes.',
|
|
120
|
-
html: options.html || '<p>This is a mock email body for testing purposes.</p>',
|
|
121
|
-
from: {
|
|
122
|
-
text: options.from || 'sender@test.com',
|
|
123
|
-
value: [{ address: options.from || 'sender@test.com', name: 'Test Sender' }]
|
|
124
|
-
},
|
|
125
|
-
to: {
|
|
126
|
-
text: options.to || 'recipient@test.com',
|
|
127
|
-
value: [{ address: options.to || 'recipient@test.com', name: 'Test Recipient' }]
|
|
128
|
-
},
|
|
129
|
-
date: options.date || new Date(),
|
|
130
|
-
messageId: options.messageId || '<mock-message-id@test.com>',
|
|
131
|
-
headers: new Map([
|
|
132
|
-
['message-id', '<mock-message-id@test.com>'],
|
|
133
|
-
['subject', options.subject || 'Mock Email Subject'],
|
|
134
|
-
['from', options.from || 'sender@test.com'],
|
|
135
|
-
['to', options.to || 'recipient@test.com']
|
|
136
|
-
]),
|
|
137
|
-
attachments: options.attachments || []
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Create mock Node-RED object for unit testing
|
|
145
|
-
*/
|
|
146
|
-
function createMockNodeRED(options = {}) {
|
|
147
|
-
return {
|
|
148
|
-
nodes: {
|
|
149
|
-
createNode: function(node, config) {
|
|
150
|
-
// Apply config properties to node
|
|
151
|
-
Object.assign(node, {
|
|
152
|
-
id: config.id || 'mock-node-id',
|
|
153
|
-
type: config.type || 'email-receiver',
|
|
154
|
-
name: config.name || 'Mock Node',
|
|
155
|
-
on: options.onHandler || function() {},
|
|
156
|
-
status: options.statusHandler || function() {},
|
|
157
|
-
error: options.errorHandler || function() {},
|
|
158
|
-
send: options.sendHandler || function() {},
|
|
159
|
-
log: options.logHandler || function() {},
|
|
160
|
-
warn: options.warnHandler || function() {},
|
|
161
|
-
debug: options.debugHandler || function() {}
|
|
162
|
-
});
|
|
163
|
-
return node;
|
|
164
|
-
},
|
|
165
|
-
registerType: function(type, constructor) {
|
|
166
|
-
// Store registration for verification in tests
|
|
167
|
-
this.lastRegisteredType = type;
|
|
168
|
-
this.lastRegisteredConstructor = constructor;
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
util: {
|
|
172
|
-
evaluateNodeProperty: function(value, type, node, msg, callback) {
|
|
173
|
-
if (type === 'json') {
|
|
174
|
-
try {
|
|
175
|
-
// Simulate parsing a JSON string into an object
|
|
176
|
-
return JSON.parse(JSON.stringify(value));
|
|
177
|
-
} catch (e) {
|
|
178
|
-
if (callback) {
|
|
179
|
-
callback(e, null);
|
|
180
|
-
}
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Simple mock implementation
|
|
186
|
-
if (callback) {
|
|
187
|
-
callback(null, value);
|
|
188
|
-
}
|
|
189
|
-
return value;
|
|
190
|
-
},
|
|
191
|
-
encrypt: function(value) {
|
|
192
|
-
return 'encrypted:' + value;
|
|
193
|
-
},
|
|
194
|
-
decrypt: function(value) {
|
|
195
|
-
return value.replace('encrypted:', '');
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
log: {
|
|
199
|
-
info: options.logInfo || function() {},
|
|
200
|
-
warn: options.logWarn || function() {},
|
|
201
|
-
error: options.logError || function() {},
|
|
202
|
-
debug: options.logDebug || function() {}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Set up module mocks for require() calls
|
|
209
|
-
*/
|
|
210
|
-
function setupModuleMocks() {
|
|
211
|
-
const mockModules = {
|
|
212
|
-
'node-imap': createMockImap(),
|
|
213
|
-
'mailparser': createMockMailparser()
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const Module = require('module');
|
|
217
|
-
const originalLoad = Module._load;
|
|
218
|
-
|
|
219
|
-
Module._load = function(request, parent) {
|
|
220
|
-
if (mockModules[request]) {
|
|
221
|
-
return mockModules[request];
|
|
222
|
-
}
|
|
223
|
-
return originalLoad.apply(this, arguments);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
// Return cleanup function
|
|
227
|
-
return function cleanup() {
|
|
228
|
-
Module._load = originalLoad;
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Create test configurations for different scenarios
|
|
234
|
-
*/
|
|
235
|
-
const testConfigs = {
|
|
236
|
-
valid: {
|
|
237
|
-
id: 'test-node-1',
|
|
238
|
-
type: 'email-receiver',
|
|
239
|
-
name: 'Test Email Receiver',
|
|
240
|
-
host: 'imap.test.com',
|
|
241
|
-
hostType: 'str',
|
|
242
|
-
port: 993,
|
|
243
|
-
portType: 'num',
|
|
244
|
-
tls: true,
|
|
245
|
-
tlsType: 'bool',
|
|
246
|
-
user: 'test@test.com',
|
|
247
|
-
userType: 'str',
|
|
248
|
-
password: 'testpass',
|
|
249
|
-
passwordType: 'str',
|
|
250
|
-
folder: 'INBOX',
|
|
251
|
-
folderType: 'str',
|
|
252
|
-
markseen: true,
|
|
253
|
-
markseenType: 'bool'
|
|
254
|
-
},
|
|
255
|
-
|
|
256
|
-
arrayFolders: {
|
|
257
|
-
id: 'test-node-3',
|
|
258
|
-
type: 'email-receiver',
|
|
259
|
-
name: 'Array Folders Test',
|
|
260
|
-
host: 'imap.test.com',
|
|
261
|
-
hostType: 'str',
|
|
262
|
-
port: 993,
|
|
263
|
-
portType: 'num',
|
|
264
|
-
user: 'test@test.com',
|
|
265
|
-
userType: 'str',
|
|
266
|
-
password: 'testpass',
|
|
267
|
-
passwordType: 'str',
|
|
268
|
-
folder: ['INBOX', 'Junk', 'Drafts'],
|
|
269
|
-
folderType: 'json',
|
|
270
|
-
markseen: false,
|
|
271
|
-
markseenType: 'bool'
|
|
272
|
-
},
|
|
273
|
-
|
|
274
|
-
invalidConfig: {
|
|
275
|
-
id: 'test-node-4',
|
|
276
|
-
type: 'email-receiver',
|
|
277
|
-
name: 'Invalid Config Test',
|
|
278
|
-
host: '', // Missing host
|
|
279
|
-
hostType: 'str',
|
|
280
|
-
port: 993,
|
|
281
|
-
portType: 'num',
|
|
282
|
-
user: 'test@test.com',
|
|
283
|
-
userType: 'str',
|
|
284
|
-
password: '', // Missing password
|
|
285
|
-
passwordType: 'str',
|
|
286
|
-
folder: 123, // Wrong type
|
|
287
|
-
folderType: 'num'
|
|
288
|
-
},
|
|
289
|
-
|
|
290
|
-
minimal: {
|
|
291
|
-
id: 'test-node-5',
|
|
292
|
-
type: 'email-receiver',
|
|
293
|
-
host: 'imap.minimal.com',
|
|
294
|
-
hostType: 'str',
|
|
295
|
-
port: 993,
|
|
296
|
-
portType: 'num',
|
|
297
|
-
user: 'minimal@test.com',
|
|
298
|
-
userType: 'str',
|
|
299
|
-
password: 'minimalpass',
|
|
300
|
-
passwordType: 'str',
|
|
301
|
-
folder: 'INBOX',
|
|
302
|
-
folderType: 'str'
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Create test flows for Node-RED integration tests
|
|
308
|
-
*/
|
|
309
|
-
const testFlows = {
|
|
310
|
-
single: [
|
|
311
|
-
testConfigs.valid
|
|
312
|
-
],
|
|
313
|
-
|
|
314
|
-
withHelper: [
|
|
315
|
-
testConfigs.valid,
|
|
316
|
-
{ id: 'h1', type: 'helper' }
|
|
317
|
-
],
|
|
318
|
-
|
|
319
|
-
connected: [
|
|
320
|
-
{ ...testConfigs.valid, wires: [['h1']] },
|
|
321
|
-
{ id: 'h1', type: 'helper' }
|
|
322
|
-
],
|
|
323
|
-
|
|
324
|
-
multiOutput: [
|
|
325
|
-
{ ...testConfigs.valid, wires: [['h1', 'h2']] },
|
|
326
|
-
{ id: 'h1', type: 'helper' },
|
|
327
|
-
{ id: 'h2', type: 'helper' }
|
|
328
|
-
]
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Utility functions for test assertions
|
|
333
|
-
*/
|
|
334
|
-
const testUtils = {
|
|
335
|
-
/**
|
|
336
|
-
* Wait for a specified amount of time
|
|
337
|
-
*/
|
|
338
|
-
wait: (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)),
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Create a promise that resolves when a node receives a message
|
|
342
|
-
*/
|
|
343
|
-
waitForMessage: (node, timeout = 1000) => {
|
|
344
|
-
return new Promise((resolve, reject) => {
|
|
345
|
-
const timer = setTimeout(() => {
|
|
346
|
-
reject(new Error('Timeout waiting for message'));
|
|
347
|
-
}, timeout);
|
|
348
|
-
|
|
349
|
-
node.on('input', (msg) => {
|
|
350
|
-
clearTimeout(timer);
|
|
351
|
-
resolve(msg);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
},
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Verify that a message has expected properties
|
|
358
|
-
*/
|
|
359
|
-
verifyMessage: (msg, expectedProps = {}) => {
|
|
360
|
-
const should = require('should');
|
|
361
|
-
should.exist(msg);
|
|
362
|
-
|
|
363
|
-
Object.keys(expectedProps).forEach(prop => {
|
|
364
|
-
if (expectedProps[prop] !== undefined) {
|
|
365
|
-
msg.should.have.property(prop, expectedProps[prop]);
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
module.exports = {
|
|
372
|
-
createMockImap,
|
|
373
|
-
createMockMailparser,
|
|
374
|
-
createMockNodeRED,
|
|
375
|
-
setupModuleMocks,
|
|
376
|
-
testConfigs,
|
|
377
|
-
testFlows,
|
|
378
|
-
testUtils
|
|
379
|
-
};
|