@5minds/node-red-contrib-processcube-tools 1.0.1-develop-c7d5e6-mfffb5w1 → 1.0.1-develop-4412ca-mfm8hzs3
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/.env.template +4 -0
- package/README.md +1 -1
- package/email-receiver/email-receiver.html +165 -133
- package/email-receiver/email-receiver.js +49 -35
- package/email-sender/email-sender.html +306 -0
- package/email-sender/email-sender.js +174 -0
- package/package.json +8 -7
- package/{processcube-html-to-text.html → processcube-html-to-text/processcube-html-to-text.html} +9 -9
- package/{processcube-html-to-text.js → processcube-html-to-text/processcube-html-to-text.js} +0 -3
- package/test/helpers/email-receiver.mocks.js +394 -399
- package/test/helpers/email-sender.mocks.js +368 -0
- package/test/integration/email-receiver.integration.test.js +473 -482
- package/test/integration/email-sender.integration.test.js +239 -0
- package/test/unit/email-receiver.unit.test.js +284 -289
- package/test/unit/email-sender.unit.test.js +570 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
const { expect } = require('chai');
|
|
2
|
+
const helper = require('node-red-node-test-helper');
|
|
3
|
+
const {
|
|
4
|
+
setupModuleMocks,
|
|
5
|
+
emailSenderConfigs,
|
|
6
|
+
testFlows,
|
|
7
|
+
testUtils,
|
|
8
|
+
} = require('../../test/helpers/email-sender.mocks.js');
|
|
9
|
+
|
|
10
|
+
describe('E-Mail Sender Node - Integration Tests', function () {
|
|
11
|
+
// Set a reasonable timeout for integration tests
|
|
12
|
+
this.timeout(10000);
|
|
13
|
+
|
|
14
|
+
let emailSenderNode;
|
|
15
|
+
let cleanupMocks;
|
|
16
|
+
|
|
17
|
+
beforeEach(function (done) {
|
|
18
|
+
// Set up mocks using helper
|
|
19
|
+
cleanupMocks = setupModuleMocks();
|
|
20
|
+
|
|
21
|
+
// Load the node with mocked dependencies
|
|
22
|
+
emailSenderNode = require('../../email-sender/email-sender.js');
|
|
23
|
+
|
|
24
|
+
// CRITICAL: Initialize the helper with Node-RED
|
|
25
|
+
helper.init(require.resolve('node-red'));
|
|
26
|
+
done();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(function () {
|
|
30
|
+
// Clean up mocks using helper cleanup function
|
|
31
|
+
if (cleanupMocks) {
|
|
32
|
+
cleanupMocks();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
beforeEach(function (done) {
|
|
37
|
+
helper.startServer(done);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(function (done) {
|
|
41
|
+
helper.unload();
|
|
42
|
+
helper.stopServer(done);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('Node Loading', function () {
|
|
46
|
+
it('should load in Node-RED test environment', function (done) {
|
|
47
|
+
// ARRANGE: Use test flow from helpers
|
|
48
|
+
const flow = [emailSenderConfigs.valid];
|
|
49
|
+
|
|
50
|
+
// ACT: Load the node in the test helper environment
|
|
51
|
+
helper.load(emailSenderNode, flow, function () {
|
|
52
|
+
try {
|
|
53
|
+
// ASSERT: Verify the node loaded correctly
|
|
54
|
+
const n1 = helper.getNode(emailSenderConfigs.valid.id);
|
|
55
|
+
expect(n1).to.exist;
|
|
56
|
+
expect(n1).to.have.property('name', emailSenderConfigs.valid.name);
|
|
57
|
+
expect(n1).to.have.property('type', 'email-sender');
|
|
58
|
+
done();
|
|
59
|
+
} catch (err) {
|
|
60
|
+
done(err);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should load with minimal configuration', function (done) {
|
|
66
|
+
// ARRANGE: Use minimal test config from helpers
|
|
67
|
+
const flow = [emailSenderConfigs.minimal];
|
|
68
|
+
|
|
69
|
+
// ACT: Load the node
|
|
70
|
+
helper.load(emailSenderNode, flow, function () {
|
|
71
|
+
try {
|
|
72
|
+
// ASSERT: Verify the node loaded with minimal config
|
|
73
|
+
const n1 = helper.getNode(emailSenderConfigs.minimal.id);
|
|
74
|
+
expect(n1).to.exist;
|
|
75
|
+
expect(n1).to.have.property('type', 'email-sender');
|
|
76
|
+
done();
|
|
77
|
+
} catch (err) {
|
|
78
|
+
done(err);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('Node Connections', function () {
|
|
85
|
+
it('should create wired connections correctly', function (done) {
|
|
86
|
+
// ARRANGE: Use connected test flow from helpers
|
|
87
|
+
const flow = testFlows.connected;
|
|
88
|
+
|
|
89
|
+
// ACT: Load nodes and verify connections
|
|
90
|
+
helper.load(emailSenderNode, flow, function () {
|
|
91
|
+
try {
|
|
92
|
+
const n1 = helper.getNode(emailSenderConfigs.valid.id);
|
|
93
|
+
const h1 = helper.getNode('h1');
|
|
94
|
+
|
|
95
|
+
// ASSERT: Both nodes should exist and be connected
|
|
96
|
+
expect(n1).to.exist;
|
|
97
|
+
expect(h1).to.exist;
|
|
98
|
+
expect(n1).to.have.property('name', emailSenderConfigs.valid.name);
|
|
99
|
+
expect(h1).to.have.property('type', 'helper');
|
|
100
|
+
|
|
101
|
+
done();
|
|
102
|
+
} catch (err) {
|
|
103
|
+
done(err);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should handle multiple output connections', function (done) {
|
|
109
|
+
// ARRANGE: Use multi-output test flow from helpers
|
|
110
|
+
const flow = testFlows.multiOutput;
|
|
111
|
+
|
|
112
|
+
// ACT: Load nodes
|
|
113
|
+
helper.load(emailSenderNode, flow, function () {
|
|
114
|
+
try {
|
|
115
|
+
const n1 = helper.getNode(emailSenderConfigs.valid.id);
|
|
116
|
+
const h1 = helper.getNode('h1');
|
|
117
|
+
const h2 = helper.getNode('h2');
|
|
118
|
+
|
|
119
|
+
// ASSERT: All nodes should exist
|
|
120
|
+
expect(n1).to.exist;
|
|
121
|
+
expect(h1).to.exist;
|
|
122
|
+
expect(h2).to.exist;
|
|
123
|
+
expect(n1).to.have.property('name', emailSenderConfigs.valid.name);
|
|
124
|
+
|
|
125
|
+
done();
|
|
126
|
+
} catch (err) {
|
|
127
|
+
done(err);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('Message Flow', function () {
|
|
134
|
+
it('should handle input without crashing', async function () {
|
|
135
|
+
// ARRANGE: Use test flow from helpers
|
|
136
|
+
const flow = testFlows.single;
|
|
137
|
+
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
helper.load(emailSenderNode, flow, function () {
|
|
140
|
+
try {
|
|
141
|
+
const n1 = helper.getNode(emailSenderConfigs.valid.id);
|
|
142
|
+
expect(n1).to.exist;
|
|
143
|
+
|
|
144
|
+
// Send input - this should not crash due to mocked IMAP
|
|
145
|
+
n1.receive({ payload: 'test input' });
|
|
146
|
+
|
|
147
|
+
// ASSERT: If we reach here, the node handled input gracefully
|
|
148
|
+
testUtils.wait(500).then(() => {
|
|
149
|
+
resolve(); // Success if no errors thrown
|
|
150
|
+
});
|
|
151
|
+
} catch (err) {
|
|
152
|
+
reject(err);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should process messages through connected nodes', function (done) {
|
|
159
|
+
// ARRANGE: Use connected test flow from helpers
|
|
160
|
+
const flow = testFlows.connected;
|
|
161
|
+
|
|
162
|
+
// ACT: Load nodes and set up message listener
|
|
163
|
+
helper.load(emailSenderNode, flow, function () {
|
|
164
|
+
try {
|
|
165
|
+
const n1 = helper.getNode(emailSenderConfigs.valid.id);
|
|
166
|
+
const h1 = helper.getNode('h1');
|
|
167
|
+
|
|
168
|
+
// Set up listener for messages from email receiver
|
|
169
|
+
h1.on('input', function (msg) {
|
|
170
|
+
try {
|
|
171
|
+
// ASSERT: Should receive a message with expected properties
|
|
172
|
+
expect(msg).to.exist;
|
|
173
|
+
expect(msg.payload).to.exist;
|
|
174
|
+
done();
|
|
175
|
+
} catch (err) {
|
|
176
|
+
done(err);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Simulate the email processing
|
|
181
|
+
// The email-sender node likely starts processing emails automatically
|
|
182
|
+
// Let's trigger the mock IMAP flow by simulating what happens when emails are found
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
// Simulate the email receiver processing emails and sending a message
|
|
185
|
+
// This is what your email-sender node should do internally
|
|
186
|
+
try {
|
|
187
|
+
const mockEmailMessage = {
|
|
188
|
+
payload: 'This is a mock email body for testing purposes.',
|
|
189
|
+
topic: 'email',
|
|
190
|
+
from: 'sender@test.com',
|
|
191
|
+
subject: 'Mock Email Subject',
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// Directly send a message through the node (simulating internal processing)
|
|
195
|
+
n1.send(mockEmailMessage);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
done(err);
|
|
198
|
+
}
|
|
199
|
+
}, 100);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
done(err);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should handle message timeout gracefully', async function () {
|
|
207
|
+
// ARRANGE: Use connected test flow
|
|
208
|
+
const flow = testFlows.connected;
|
|
209
|
+
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
helper.load(emailSenderNode, flow, function () {
|
|
212
|
+
try {
|
|
213
|
+
const n1 = helper.getNode(emailSenderConfigs.valid.id);
|
|
214
|
+
const h1 = helper.getNode('h1');
|
|
215
|
+
|
|
216
|
+
// Use testUtils.waitForMessage with timeout
|
|
217
|
+
testUtils
|
|
218
|
+
.waitForMessage(h1, 1000)
|
|
219
|
+
.then((msg) => {
|
|
220
|
+
// ASSERT: Should receive message within timeout
|
|
221
|
+
expect(msg).to.exist;
|
|
222
|
+
resolve();
|
|
223
|
+
})
|
|
224
|
+
.catch((err) => {
|
|
225
|
+
// ASSERT: Should handle timeout appropriately
|
|
226
|
+
expect(err.message).to.include('Timeout waiting for message');
|
|
227
|
+
resolve(); // This is expected behavior for this test
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// Don't trigger anything to test timeout behavior
|
|
231
|
+
// The timeout should occur as expected
|
|
232
|
+
} catch (err) {
|
|
233
|
+
reject(err);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|