@5minds/node-red-contrib-processcube-tools 1.0.1-feature-050c1a-mfe18hnk → 1.0.1-feature-f506be-mfe3agh6
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 +257 -0
- package/email-sender/email-sender.js +91 -0
- package/package.json +5 -26
- package/email-receiver/email-receiver.html +0 -187
- package/email-receiver/email-receiver.js +0 -236
- package/test/helpers/email-receiver.mocks.js +0 -379
- package/test/integration/email-receiver.integration.test.js +0 -479
- package/test/unit/email-receiver.unit.test.js +0 -279
- /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,279 +0,0 @@
|
|
|
1
|
-
const should = require('should');
|
|
2
|
-
const {
|
|
3
|
-
createMockImap,
|
|
4
|
-
createMockMailparser,
|
|
5
|
-
createMockNodeRED,
|
|
6
|
-
setupModuleMocks,
|
|
7
|
-
testConfigs,
|
|
8
|
-
testUtils
|
|
9
|
-
} = require('../helpers/email-receiver.mocks.js');
|
|
10
|
-
|
|
11
|
-
describe('Email Receiver Node - Unit Tests with Helpers', function() {
|
|
12
|
-
this.timeout(10000);
|
|
13
|
-
|
|
14
|
-
let emailReceiverNode;
|
|
15
|
-
let cleanupMocks;
|
|
16
|
-
|
|
17
|
-
before(function() {
|
|
18
|
-
// Set up module mocks using helper
|
|
19
|
-
cleanupMocks = setupModuleMocks();
|
|
20
|
-
|
|
21
|
-
// Load the node with mocked dependencies
|
|
22
|
-
emailReceiverNode = require('../../email-receiver/email-receiver.js');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
after(function() {
|
|
26
|
-
// Clean up mocks
|
|
27
|
-
if (cleanupMocks) {
|
|
28
|
-
cleanupMocks();
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('Module Export', function() {
|
|
33
|
-
it('should export a function', function() {
|
|
34
|
-
emailReceiverNode.should.be.type('function');
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('Node Registration', function() {
|
|
39
|
-
it('should register node type without errors', function() {
|
|
40
|
-
// ARRANGE: Create mock Node-RED with tracking
|
|
41
|
-
const mockRED = createMockNodeRED();
|
|
42
|
-
|
|
43
|
-
// ACT: Register the node
|
|
44
|
-
emailReceiverNode(mockRED);
|
|
45
|
-
|
|
46
|
-
// ASSERT: Verify registration
|
|
47
|
-
mockRED.nodes.lastRegisteredType.should.equal('email-receiver');
|
|
48
|
-
mockRED.nodes.lastRegisteredConstructor.should.be.type('function');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('Node Instantiation', function() {
|
|
53
|
-
it('should handle node instantiation with valid config', function() {
|
|
54
|
-
// ARRANGE: Track node creation
|
|
55
|
-
let createdNode = null;
|
|
56
|
-
const mockRED = createMockNodeRED({
|
|
57
|
-
onHandler: function(event, callback) {
|
|
58
|
-
createdNode = this;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// ACT: Register and create node instance
|
|
63
|
-
emailReceiverNode(mockRED);
|
|
64
|
-
new mockRED.nodes.lastRegisteredConstructor(testConfigs.valid);
|
|
65
|
-
|
|
66
|
-
// ASSERT: Verify node was created with correct properties
|
|
67
|
-
should.exist(createdNode);
|
|
68
|
-
createdNode.should.have.property('name', testConfigs.valid.name);
|
|
69
|
-
createdNode.should.have.property('id', testConfigs.valid.id);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should handle minimal config', function() {
|
|
73
|
-
// ARRANGE: Use minimal test config
|
|
74
|
-
let createdNode = null;
|
|
75
|
-
const mockRED = createMockNodeRED({
|
|
76
|
-
onHandler: function(event, callback) {
|
|
77
|
-
createdNode = this;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// ACT: Register and create node with minimal config
|
|
82
|
-
emailReceiverNode(mockRED);
|
|
83
|
-
new mockRED.nodes.lastRegisteredConstructor(testConfigs.minimal);
|
|
84
|
-
|
|
85
|
-
// ASSERT: Verify node creation
|
|
86
|
-
should.exist(createdNode);
|
|
87
|
-
createdNode.should.have.property('id', testConfigs.minimal.id);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('Folder Configuration', function() {
|
|
92
|
-
it('should handle array of folders', async function() {
|
|
93
|
-
// ARRANGE: Set up message tracking
|
|
94
|
-
let sentMessage = null;
|
|
95
|
-
const mockRED = createMockNodeRED({
|
|
96
|
-
sendHandler: function(msg) {
|
|
97
|
-
sentMessage = msg;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// ACT: Register node and create instance with array folders
|
|
102
|
-
emailReceiverNode(mockRED);
|
|
103
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
104
|
-
const nodeInstance = new nodeConstructor(testConfigs.arrayFolders);
|
|
105
|
-
|
|
106
|
-
// Wait for processing
|
|
107
|
-
await testUtils.wait(50);
|
|
108
|
-
|
|
109
|
-
// ASSERT: Should handle array folders without error
|
|
110
|
-
should.exist(nodeInstance);
|
|
111
|
-
nodeInstance.should.have.property('name', testConfigs.arrayFolders.name);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('Error Handling', function() {
|
|
116
|
-
it('should call node.error for invalid folder type', function(done) {
|
|
117
|
-
// ARRANGE: Set up error tracking
|
|
118
|
-
const mockRED = createMockNodeRED({
|
|
119
|
-
errorHandler: function(err) {
|
|
120
|
-
// ASSERT: Should receive appropriate error message
|
|
121
|
-
err.should.containEql("The 'folders' property must be an array of strings.");
|
|
122
|
-
done();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// ACT: Register node and create instance with invalid config
|
|
127
|
-
emailReceiverNode(mockRED);
|
|
128
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
129
|
-
new nodeConstructor(testConfigs.invalidConfig);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should call node.error for missing config', function(done) {
|
|
133
|
-
// ARRANGE: Set up error and status tracking
|
|
134
|
-
let statusCalled = false;
|
|
135
|
-
const mockRED = createMockNodeRED({
|
|
136
|
-
statusHandler: function(status) {
|
|
137
|
-
statusCalled = true;
|
|
138
|
-
if (status.fill) {
|
|
139
|
-
status.fill.should.equal('red');
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
errorHandler: function(err) {
|
|
143
|
-
// ASSERT: Should receive config error
|
|
144
|
-
err.should.containEql('Missing required IMAP config');
|
|
145
|
-
statusCalled.should.be.true();
|
|
146
|
-
done();
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// ACT: Register node and create instance with invalid config
|
|
151
|
-
emailReceiverNode(mockRED);
|
|
152
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
153
|
-
new nodeConstructor(testConfigs.invalidConfig);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe('Message Processing', function() {
|
|
158
|
-
it('should process email message correctly', async function() {
|
|
159
|
-
// ARRANGE: Set up message capture
|
|
160
|
-
let processedMessage = null;
|
|
161
|
-
const mockRED = createMockNodeRED({
|
|
162
|
-
sendHandler: function(msg) {
|
|
163
|
-
processedMessage = msg;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// ACT: Create node and simulate email processing
|
|
168
|
-
emailReceiverNode(mockRED);
|
|
169
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
170
|
-
const nodeInstance = new nodeConstructor(testConfigs.valid);
|
|
171
|
-
|
|
172
|
-
// Simulate input trigger (this would depend on your node's implementation)
|
|
173
|
-
// The actual trigger mechanism would need to match your node's design
|
|
174
|
-
|
|
175
|
-
await testUtils.wait(100);
|
|
176
|
-
|
|
177
|
-
// ASSERT: Message processing behavior would be verified here
|
|
178
|
-
// The specific assertions depend on your node's output format
|
|
179
|
-
should.exist(nodeInstance);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('should handle multiple messages', async function() {
|
|
183
|
-
// ARRANGE: Set up message collection
|
|
184
|
-
const messages = [];
|
|
185
|
-
const mockRED = createMockNodeRED({
|
|
186
|
-
sendHandler: function(msg) {
|
|
187
|
-
messages.push(msg);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// ACT: Create node and simulate multiple emails
|
|
192
|
-
emailReceiverNode(mockRED);
|
|
193
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
194
|
-
const nodeInstance = new nodeConstructor(testConfigs.valid);
|
|
195
|
-
|
|
196
|
-
await testUtils.wait(150);
|
|
197
|
-
|
|
198
|
-
// ASSERT: Should handle multiple messages appropriately
|
|
199
|
-
should.exist(nodeInstance);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('IMAP Connection', function() {
|
|
204
|
-
it('should handle connection success', function(done) {
|
|
205
|
-
// ARRANGE: Set up connection tracking
|
|
206
|
-
const mockRED = createMockNodeRED({
|
|
207
|
-
statusHandler: function(status) {
|
|
208
|
-
if (status.fill === 'green') {
|
|
209
|
-
// ASSERT: Should show connected status
|
|
210
|
-
status.text.should.containEql('connected');
|
|
211
|
-
done();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// ACT: Create node which should attempt connection
|
|
217
|
-
emailReceiverNode(mockRED);
|
|
218
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
219
|
-
new nodeConstructor(testConfigs.valid);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should handle connection errors', function(done) {
|
|
223
|
-
// ARRANGE: Set up error tracking
|
|
224
|
-
const mockRED = createMockNodeRED({
|
|
225
|
-
errorHandler: function(err) {
|
|
226
|
-
// ASSERT: Should handle connection errors gracefully
|
|
227
|
-
should.exist(err);
|
|
228
|
-
done();
|
|
229
|
-
},
|
|
230
|
-
statusHandler: function(status) {
|
|
231
|
-
if (status.fill === 'red') {
|
|
232
|
-
// Connection failed status
|
|
233
|
-
status.text.should.containEql('error');
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
// ACT: Create node with config that should fail
|
|
239
|
-
emailReceiverNode(mockRED);
|
|
240
|
-
const nodeConstructor = mockRED.nodes.lastRegisteredConstructor;
|
|
241
|
-
|
|
242
|
-
// Use invalid config to trigger connection error
|
|
243
|
-
const invalidConfig = { ...testConfigs.valid, host: 'invalid.host.com' };
|
|
244
|
-
new nodeConstructor(invalidConfig);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe('Message Verification Utilities', function() {
|
|
249
|
-
it('should verify message properties using testUtils', function() {
|
|
250
|
-
// ARRANGE: Create a test message
|
|
251
|
-
const testMessage = {
|
|
252
|
-
payload: 'test content',
|
|
253
|
-
topic: 'email/received',
|
|
254
|
-
from: 'test@example.com'
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// ACT & ASSERT: Use helper to verify message properties
|
|
258
|
-
testUtils.verifyMessage(testMessage, {
|
|
259
|
-
payload: 'test content',
|
|
260
|
-
topic: 'email/received'
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// Should not throw any errors if verification passes
|
|
264
|
-
testMessage.should.have.property('from', 'test@example.com');
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('should use wait utility for async operations', async function() {
|
|
268
|
-
// ARRANGE: Record start time
|
|
269
|
-
const startTime = Date.now();
|
|
270
|
-
|
|
271
|
-
// ACT: Use the wait utility
|
|
272
|
-
await testUtils.wait(100);
|
|
273
|
-
|
|
274
|
-
// ASSERT: Should have waited approximately the right amount of time
|
|
275
|
-
const elapsed = Date.now() - startTime;
|
|
276
|
-
elapsed.should.be.approximately(100, 50); // Allow 50ms tolerance
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
});
|
/package/{processcube-html-to-text.html → processcube-html-to-text/processcube-html-to-text.html}
RENAMED
|
File without changes
|
/package/{processcube-html-to-text.js → processcube-html-to-text/processcube-html-to-text.js}
RENAMED
|
File without changes
|