node-red-contrib-boolean-logic-ultimate 1.2.3 → 1.2.5

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.
@@ -0,0 +1,251 @@
1
+ 'use strict';
2
+
3
+ const { expect } = require('chai');
4
+ const { helper, loadRailwaySwitch } = require('./helpers');
5
+
6
+ describe('RailwaySwitchUltimate node', function () {
7
+ this.timeout(5000);
8
+
9
+ before(function (done) {
10
+ helper.startServer(done);
11
+ });
12
+
13
+ after(function (done) {
14
+ helper.stopServer(done);
15
+ });
16
+
17
+ afterEach(function () {
18
+ return helper.unload();
19
+ });
20
+
21
+ it('routes messages to the selected output pin', function (done) {
22
+ const flowId = 'flow-rws-1';
23
+ const flow = [
24
+ { id: flowId, type: 'tab', label: 'flow-rws-1' },
25
+ {
26
+ id: 'rws',
27
+ type: 'RailwaySwitchUltimate',
28
+ z: flowId,
29
+ name: 'rws',
30
+ triggertopic: 'switcher',
31
+ outputs: 5,
32
+ initializewith: '0',
33
+ payloadPropName: 'payload',
34
+ translatorConfig: '',
35
+ wires: [['out0'], ['out1'], ['out2'], ['out3'], ['out4']],
36
+ },
37
+ { id: 'in', type: 'helper', z: flowId, wires: [['rws']] },
38
+ { id: 'out0', type: 'helper', z: flowId },
39
+ { id: 'out1', type: 'helper', z: flowId },
40
+ { id: 'out2', type: 'helper', z: flowId },
41
+ { id: 'out3', type: 'helper', z: flowId },
42
+ { id: 'out4', type: 'helper', z: flowId },
43
+ ];
44
+
45
+ loadRailwaySwitch(flow).then(() => {
46
+ const rws = helper.getNode('rws');
47
+ const out0 = helper.getNode('out0');
48
+ const out1 = helper.getNode('out1');
49
+ const out2 = helper.getNode('out2');
50
+ const out3 = helper.getNode('out3');
51
+ const out4 = helper.getNode('out4');
52
+
53
+ const received = { out0: [], out1: [], out2: [], out3: [], out4: [] };
54
+ out0.on('input', (msg) => received.out0.push(msg));
55
+ out1.on('input', (msg) => received.out1.push(msg));
56
+ out2.on('input', (msg) => received.out2.push(msg));
57
+ out3.on('input', (msg) => received.out3.push(msg));
58
+ out4.on('input', (msg) => received.out4.push(msg));
59
+
60
+ rws.receive({ topic: 'switcher', payload: 2 });
61
+ rws.receive({ topic: 'data', payload: 'train' });
62
+
63
+ setTimeout(() => {
64
+ try {
65
+ expect(received.out0).to.have.length(0);
66
+ expect(received.out1).to.have.length(0);
67
+ expect(received.out3).to.have.length(0);
68
+ expect(received.out4).to.have.length(0);
69
+ expect(received.out2).to.have.length(1);
70
+ expect(received.out2[0]).to.include({ topic: 'data', payload: 'train' });
71
+ done();
72
+ } catch (err) {
73
+ done(err);
74
+ }
75
+ }, 50);
76
+ }).catch(done);
77
+ });
78
+
79
+ it('ignores an out-of-range selector and keeps the current pin', function (done) {
80
+ const flowId = 'flow-rws-2';
81
+ const flow = [
82
+ { id: flowId, type: 'tab', label: 'flow-rws-2' },
83
+ {
84
+ id: 'rws',
85
+ type: 'RailwaySwitchUltimate',
86
+ z: flowId,
87
+ name: 'rws',
88
+ triggertopic: 'switcher',
89
+ outputs: 5,
90
+ initializewith: '1',
91
+ payloadPropName: 'payload',
92
+ translatorConfig: '',
93
+ wires: [['out0'], ['out1'], ['out2'], ['out3'], ['out4']],
94
+ },
95
+ { id: 'in', type: 'helper', z: flowId, wires: [['rws']] },
96
+ { id: 'out0', type: 'helper', z: flowId },
97
+ { id: 'out1', type: 'helper', z: flowId },
98
+ { id: 'out2', type: 'helper', z: flowId },
99
+ { id: 'out3', type: 'helper', z: flowId },
100
+ { id: 'out4', type: 'helper', z: flowId },
101
+ ];
102
+
103
+ loadRailwaySwitch(flow).then(() => {
104
+ const rws = helper.getNode('rws');
105
+ const out0 = helper.getNode('out0');
106
+ const out1 = helper.getNode('out1');
107
+ const out2 = helper.getNode('out2');
108
+ const out3 = helper.getNode('out3');
109
+ const out4 = helper.getNode('out4');
110
+
111
+ const received = { out0: [], out1: [], out2: [], out3: [], out4: [] };
112
+ out0.on('input', (msg) => received.out0.push(msg));
113
+ out1.on('input', (msg) => received.out1.push(msg));
114
+ out2.on('input', (msg) => received.out2.push(msg));
115
+ out3.on('input', (msg) => received.out3.push(msg));
116
+ out4.on('input', (msg) => received.out4.push(msg));
117
+
118
+ rws.receive({ topic: 'switcher', payload: 9 }); // out of range
119
+ rws.receive({ topic: 'data', payload: 'train' });
120
+
121
+ setTimeout(() => {
122
+ try {
123
+ expect(received.out0).to.have.length(0);
124
+ expect(received.out2).to.have.length(0);
125
+ expect(received.out3).to.have.length(0);
126
+ expect(received.out4).to.have.length(0);
127
+ expect(received.out1).to.have.length(1);
128
+ expect(received.out1[0]).to.include({ topic: 'data', payload: 'train' });
129
+ done();
130
+ } catch (err) {
131
+ done(err);
132
+ }
133
+ }, 50);
134
+ }).catch(done);
135
+ });
136
+
137
+ it('is backward compatible when outputCount is missing (defaults to 5)', function (done) {
138
+ const flowId = 'flow-rws-3';
139
+ const flow = [
140
+ { id: flowId, type: 'tab', label: 'flow-rws-3' },
141
+ {
142
+ id: 'rws',
143
+ type: 'RailwaySwitchUltimate',
144
+ z: flowId,
145
+ name: 'rws',
146
+ triggertopic: 'switcher',
147
+ initializewith: '4',
148
+ payloadPropName: 'payload',
149
+ translatorConfig: '',
150
+ wires: [['out0'], ['out1'], ['out2'], ['out3'], ['out4']],
151
+ },
152
+ { id: 'out0', type: 'helper', z: flowId },
153
+ { id: 'out1', type: 'helper', z: flowId },
154
+ { id: 'out2', type: 'helper', z: flowId },
155
+ { id: 'out3', type: 'helper', z: flowId },
156
+ { id: 'out4', type: 'helper', z: flowId },
157
+ ];
158
+
159
+ loadRailwaySwitch(flow).then(() => {
160
+ const rws = helper.getNode('rws');
161
+ const out4 = helper.getNode('out4');
162
+
163
+ out4.on('input', (msg) => {
164
+ try {
165
+ expect(msg).to.include({ topic: 'data', payload: 'train' });
166
+ done();
167
+ } catch (err) {
168
+ done(err);
169
+ }
170
+ });
171
+
172
+ rws.receive({ topic: 'data', payload: 'train' });
173
+ }).catch(done);
174
+ });
175
+
176
+ it('supports configuring outputs to 1', function (done) {
177
+ const flowId = 'flow-rws-4';
178
+ const flow = [
179
+ { id: flowId, type: 'tab', label: 'flow-rws-4' },
180
+ {
181
+ id: 'rws',
182
+ type: 'RailwaySwitchUltimate',
183
+ z: flowId,
184
+ name: 'rws',
185
+ triggertopic: 'switcher',
186
+ outputs: 1,
187
+ initializewith: '0',
188
+ payloadPropName: 'payload',
189
+ translatorConfig: '',
190
+ wires: [['out0']],
191
+ },
192
+ { id: 'out0', type: 'helper', z: flowId },
193
+ ];
194
+
195
+ loadRailwaySwitch(flow).then(() => {
196
+ const rws = helper.getNode('rws');
197
+ const out0 = helper.getNode('out0');
198
+
199
+ out0.on('input', (msg) => {
200
+ try {
201
+ expect(msg).to.include({ topic: 'data', payload: 'train' });
202
+ done();
203
+ } catch (err) {
204
+ done(err);
205
+ }
206
+ });
207
+
208
+ rws.receive({ topic: 'switcher', payload: 1 }); // out of range for outputs=1
209
+ rws.receive({ topic: 'data', payload: 'train' });
210
+ }).catch(done);
211
+ });
212
+
213
+ it('is backward compatible with legacy outputCount when outputs is missing', function (done) {
214
+ const flowId = 'flow-rws-5';
215
+ const flow = [
216
+ { id: flowId, type: 'tab', label: 'flow-rws-5' },
217
+ {
218
+ id: 'rws',
219
+ type: 'RailwaySwitchUltimate',
220
+ z: flowId,
221
+ name: 'rws',
222
+ triggertopic: 'switcher',
223
+ outputCount: 3,
224
+ initializewith: '0',
225
+ payloadPropName: 'payload',
226
+ translatorConfig: '',
227
+ wires: [['out0'], ['out1'], ['out2']],
228
+ },
229
+ { id: 'out0', type: 'helper', z: flowId },
230
+ { id: 'out1', type: 'helper', z: flowId },
231
+ { id: 'out2', type: 'helper', z: flowId },
232
+ ];
233
+
234
+ loadRailwaySwitch(flow).then(() => {
235
+ const rws = helper.getNode('rws');
236
+ const out2 = helper.getNode('out2');
237
+
238
+ out2.on('input', (msg) => {
239
+ try {
240
+ expect(msg).to.include({ topic: 'data', payload: 'train' });
241
+ done();
242
+ } catch (err) {
243
+ done(err);
244
+ }
245
+ });
246
+
247
+ rws.receive({ topic: 'switcher', payload: 2 });
248
+ rws.receive({ topic: 'data', payload: 'train' });
249
+ }).catch(done);
250
+ });
251
+ });
@@ -41,7 +41,7 @@ describe('RateLimiterUltimate node', function () {
41
41
  ];
42
42
 
43
43
  loadRateLimiter(flow).then(() => {
44
- const input = helper.getNode('in');
44
+ const rate = helper.getNode('rate');
45
45
  const out = helper.getNode('out');
46
46
  const diag = helper.getNode('diag');
47
47
 
@@ -56,7 +56,7 @@ describe('RateLimiterUltimate node', function () {
56
56
  }
57
57
  });
58
58
 
59
- input.receive({ topic: 'sensor', payload: 'first' });
59
+ rate.receive({ topic: 'sensor', payload: 'first' });
60
60
  }).catch(done);
61
61
  });
62
62
 
@@ -83,7 +83,7 @@ describe('RateLimiterUltimate node', function () {
83
83
  ];
84
84
 
85
85
  loadRateLimiter(flow).then(() => {
86
- const input = helper.getNode('in');
86
+ const rate = helper.getNode('rate');
87
87
  const out = helper.getNode('out');
88
88
  const diag = helper.getNode('diag');
89
89
  let seenForward = 0;
@@ -107,9 +107,9 @@ describe('RateLimiterUltimate node', function () {
107
107
  }
108
108
  });
109
109
 
110
- input.receive({ topic: 'sensor', payload: 'first' });
110
+ rate.receive({ topic: 'sensor', payload: 'first' });
111
111
  setTimeout(() => {
112
- input.receive({ topic: 'sensor', payload: 'second' });
112
+ rate.receive({ topic: 'sensor', payload: 'second' });
113
113
  }, 20);
114
114
  }).catch(done);
115
115
  });
@@ -138,7 +138,7 @@ describe('RateLimiterUltimate node', function () {
138
138
  ];
139
139
 
140
140
  loadRateLimiter(flow).then(() => {
141
- const input = helper.getNode('in');
141
+ const rate = helper.getNode('rate');
142
142
  const out = helper.getNode('out');
143
143
  const diag = helper.getNode('diag');
144
144
  const start = Date.now();
@@ -160,9 +160,9 @@ describe('RateLimiterUltimate node', function () {
160
160
  }
161
161
  });
162
162
 
163
- input.receive({ topic: 'sensor', payload: 'one' });
163
+ rate.receive({ topic: 'sensor', payload: 'one' });
164
164
  setTimeout(() => {
165
- input.receive({ topic: 'sensor', payload: 'two' });
165
+ rate.receive({ topic: 'sensor', payload: 'two' });
166
166
  }, 20);
167
167
  }).catch(done);
168
168
  });
@@ -6,7 +6,21 @@ const { helper } = require('./helpers');
6
6
  const staircaseNode = require('../boolean-logic-ultimate/StaircaseLightUltimate.js');
7
7
 
8
8
  function loadStaircase(flow, credentials) {
9
- return helper.load(staircaseNode, flow, credentials || {});
9
+ const normalizedFlow = flow.map((node, index) => {
10
+ if (
11
+ node &&
12
+ node.type &&
13
+ node.type !== 'tab' &&
14
+ node.type !== 'subflow' &&
15
+ node.type !== 'group' &&
16
+ node.z &&
17
+ !(Object.prototype.hasOwnProperty.call(node, 'x') && Object.prototype.hasOwnProperty.call(node, 'y'))
18
+ ) {
19
+ return { ...node, x: 100 + index * 10, y: 100 + index * 10 };
20
+ }
21
+ return node;
22
+ });
23
+ return helper.load(staircaseNode, normalizedFlow, credentials || {});
10
24
  }
11
25
 
12
26
  describe('StaircaseLightUltimate node', function () {
@@ -52,7 +66,7 @@ describe('StaircaseLightUltimate node', function () {
52
66
  ];
53
67
 
54
68
  loadStaircase(flow).then(() => {
55
- const input = helper.getNode('in');
69
+ const stair = helper.getNode('stair');
56
70
  const outOn = helper.getNode('outOn');
57
71
  const outWarn = helper.getNode('outWarn');
58
72
  const events = [];
@@ -76,7 +90,7 @@ describe('StaircaseLightUltimate node', function () {
76
90
  }
77
91
  }, 400);
78
92
 
79
- input.receive({ payload: true });
93
+ stair.receive({ payload: true });
80
94
  }).catch(done);
81
95
  });
82
96
 
@@ -105,8 +119,7 @@ describe('StaircaseLightUltimate node', function () {
105
119
  ];
106
120
 
107
121
  loadStaircase(flow).then(() => {
108
- const input = helper.getNode('in');
109
- const control = helper.getNode('control');
122
+ const stair = helper.getNode('stair');
110
123
  const out = helper.getNode('out');
111
124
  const events = [];
112
125
 
@@ -114,10 +127,10 @@ describe('StaircaseLightUltimate node', function () {
114
127
  events.push({ type: msg.event, at: Date.now() });
115
128
  });
116
129
 
117
- input.receive({ payload: true });
130
+ stair.receive({ payload: true });
118
131
 
119
132
  setTimeout(() => {
120
- control.receive({ topic: 'stairs', command: 'extend' });
133
+ stair.receive({ topic: 'stairs', command: 'extend' });
121
134
  }, 80);
122
135
 
123
136
  setTimeout(() => {