@yousolution/node-red-contrib-you-sap-service-layer 0.2.2 → 0.2.4

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.
Files changed (50) hide show
  1. package/.prettierrc +6 -6
  2. package/.vscode/launch.json +23 -23
  3. package/CHANGELOG.md +61 -52
  4. package/README.md +126 -126
  5. package/docker-compose.yml +14 -14
  6. package/examples/example.json +625 -625
  7. package/nodes/SQLQuery.html +179 -179
  8. package/nodes/SQLQuery.js +46 -46
  9. package/nodes/authenticateSap.html +146 -146
  10. package/nodes/authenticateSap.js +129 -129
  11. package/nodes/closeSap.html +128 -97
  12. package/nodes/closeSap.js +36 -36
  13. package/nodes/createSQLQuery.html +165 -165
  14. package/nodes/createSQLQuery.js +70 -70
  15. package/nodes/createSap.html +391 -391
  16. package/nodes/createSap.js +40 -40
  17. package/nodes/crossJoinSap.html +394 -394
  18. package/nodes/crossJoinSap.js +37 -37
  19. package/nodes/deleteSap.html +406 -406
  20. package/nodes/deleteSap.js +35 -35
  21. package/nodes/getSap.html +427 -427
  22. package/nodes/getSap.js +34 -34
  23. package/nodes/listSap.html +402 -402
  24. package/nodes/listSap.js +37 -37
  25. package/nodes/manageErrors.js +38 -38
  26. package/nodes/manipulateEntitySap.html +176 -176
  27. package/nodes/manipulateEntitySap.js +46 -46
  28. package/nodes/nextLink.html +100 -100
  29. package/nodes/nextLink.js +18 -18
  30. package/nodes/patchSap.html +424 -424
  31. package/nodes/patchSap.js +40 -40
  32. package/nodes/serviceSap.html +160 -206
  33. package/nodes/serviceSap.js +39 -39
  34. package/nodes/support.js +363 -363
  35. package/package.json +65 -65
  36. package/resources/entities.json +59 -59
  37. package/resources/services.json +343 -343
  38. package/test/authenticateSap.spec.js +307 -307
  39. package/test/closeSap.spec.js +156 -156
  40. package/test/createSQLQuery.spec.js +174 -174
  41. package/test/createSap.spec.js +183 -183
  42. package/test/crossJoinSap.spec.js +156 -156
  43. package/test/deleteSap.spec.js +156 -156
  44. package/test/getSap.spec.js +156 -156
  45. package/test/listSap.spec.js +156 -156
  46. package/test/manipulateEntitySap.spec.js +191 -191
  47. package/test/patchSap.spec.js +184 -184
  48. package/test/serviceSap.spec.js +170 -170
  49. package/test/support.spec.js +1419 -1419
  50. package/data/.gitkeep +0 -0
@@ -1,307 +1,307 @@
1
- const should = require('should');
2
- const helper = require('node-red-node-test-helper');
3
- const authenticateSap = require('../nodes/authenticateSap');
4
- const Context = require('../node_modules/./@node-red/runtime/lib/nodes/context/index');
5
- const sinon = require('sinon');
6
- const Support = require('../nodes/support');
7
-
8
- helper.init(require.resolve('node-red'));
9
-
10
- describe('authenticateSap Node', () => {
11
- beforeEach((done) => {
12
- helper.startServer(done);
13
- });
14
-
15
- function initContext(done) {
16
- Context.init({
17
- contextStorage: {
18
- memory0: {
19
- module: 'memory',
20
- },
21
- memory1: {
22
- module: 'memory',
23
- },
24
- },
25
- });
26
- Context.load().then(function () {
27
- done();
28
- });
29
- }
30
-
31
- afterEach((done) => {
32
- helper
33
- .unload()
34
- .then(function () {
35
- return Context.clean({ allNodes: {} });
36
- })
37
- .then(function () {
38
- return Context.close();
39
- })
40
- .then(function () {
41
- helper.stopServer(done);
42
- });
43
-
44
- // Restore the default sandbox here
45
- sinon.restore();
46
-
47
- // helper.unload();
48
- // helper.stopServer(done);
49
- });
50
-
51
- it('should be loaded', (done) => {
52
- const flow = [
53
- {
54
- id: 'n1',
55
- type: 'authenticateSap',
56
- name: 'authenticateSap',
57
- wires: [['n2']],
58
- z: 'flow',
59
- rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
60
- },
61
- ];
62
-
63
- helper.load(authenticateSap, flow, () => {
64
- initContext(function () {
65
- const n1 = helper.getNode('n1');
66
-
67
- // console.log(helper.log().args);
68
-
69
- // n1.context().flow.set('A', 1, 'memory1', function (error) {
70
- // console.log(error);
71
- // });
72
-
73
- // console.log(n1.context().flow.get('A', 'memory1'));
74
- // console.log('- - - B- - - -');
75
-
76
- // n1.id
77
- // flow.push({
78
- // [`_YOU_SapServiceLayer_${n1.id}.headers`]:
79
- // })
80
-
81
- try {
82
- // n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Set credentials1' });
83
- // should.equal(n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Missing credentials' }), true);
84
- n1.should.have.property('name', 'authenticateSap');
85
- done();
86
- } catch (err) {
87
- done(err);
88
- }
89
- });
90
- });
91
- });
92
-
93
- it('should no have credentials', (done) => {
94
- const flow = [
95
- {
96
- id: 'n1',
97
- type: 'authenticateSap',
98
- name: 'authenticateSap',
99
- wires: [['n2']],
100
- z: 'flow',
101
- rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
102
- },
103
- ];
104
- helper.load(authenticateSap, flow, () => {
105
- initContext(function () {
106
- const n1 = helper.getNode('n1');
107
-
108
- try {
109
- should.equal(n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Missing credentials' }), true);
110
- n1.should.have.property('name', 'authenticateSap');
111
- done();
112
- } catch (err) {
113
- done(err);
114
- }
115
- });
116
- });
117
- });
118
-
119
- it('should no have credentials when send message', (done) => {
120
- const flow = [
121
- {
122
- id: 'n1',
123
- type: 'authenticateSap',
124
- name: 'authenticateSap',
125
- wires: [['n2']],
126
- z: 'flow',
127
- rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
128
- },
129
- ];
130
- helper.load(authenticateSap, flow, () => {
131
- const n1 = helper.getNode('n1');
132
-
133
- n1.receive({});
134
-
135
- n1.on('call:error', (error) => {
136
- try {
137
- should.equal(n1.status.lastCall.calledWith({ fill: 'red', shape: 'dot', text: 'Missing credentials' }), true);
138
- error.should.have.property('firstArg', new Error('Missing credentials'));
139
- done();
140
- } catch (err) {
141
- done(err);
142
- }
143
- });
144
- });
145
- });
146
-
147
- it('should generic error ', (done) => {
148
- const flow = [
149
- {
150
- id: 'n1',
151
- type: 'authenticateSap',
152
- name: 'authenticateSap',
153
- wires: [['n2']],
154
- z: 'flow',
155
- rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
156
- },
157
- { id: 'n2', type: 'helper' },
158
- ];
159
- helper.load(authenticateSap, flow, () => {
160
- const n2 = helper.getNode('n2');
161
- const n1 = helper.getNode('n1');
162
- n1.credentials.user = 'user';
163
- n1.credentials.password = 'password';
164
- n1.credentials.company = 'company';
165
-
166
- sinon.stub(Support, 'login').rejects(new Error('Custom error'));
167
-
168
- // n1.context().flow.set(`_YOU_SapServiceLayer_${n1.id}.headers`, true, 'memory1', function (error) {
169
- // // console.log(error);
170
- // });
171
-
172
- n1.receive({});
173
-
174
- n2.on('input', (msg) => {
175
- try {
176
- msg.should.have.property('payload', new Error('Custom error'));
177
- done();
178
- } catch (err) {
179
- done(err);
180
- }
181
- });
182
-
183
- n1.on('call:error', (error) => {
184
- try {
185
- error.should.have.property('firstArg', new Error('Custom error'));
186
- } catch (err) {
187
- done(err);
188
- }
189
- });
190
- });
191
- });
192
-
193
- it('should have without headers connected', (done) => {
194
- const flow = [
195
- {
196
- id: 'n1',
197
- type: 'authenticateSap',
198
- name: 'authenticateSap',
199
- wires: [['n2']],
200
- z: 'flow',
201
- rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
202
- },
203
- { id: 'n2', type: 'helper' },
204
- ];
205
- helper.load(authenticateSap, flow, () => {
206
- const n2 = helper.getNode('n2');
207
- const n1 = helper.getNode('n1');
208
- n1.credentials.user = 'user';
209
- n1.credentials.password = 'password';
210
- n1.credentials.company = 'company';
211
-
212
- sinon.stub(Support, 'login').resolves({
213
- headers: {
214
- 'Content-Type': 'application/json',
215
- 'Content-Length': 100,
216
- },
217
- });
218
-
219
- n1.receive({});
220
-
221
- n2.on('input', (msg) => {
222
- try {
223
- msg.should.have.property('_msgid');
224
- done();
225
- } catch (err) {
226
- done(err);
227
- }
228
- });
229
- });
230
- });
231
-
232
- it('should have with headers connected', (done) => {
233
- const flow = [
234
- {
235
- id: 'n1',
236
- type: 'authenticateSap',
237
- name: 'authenticateSap',
238
- wires: [['n2']],
239
- z: 'flow',
240
- rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
241
- },
242
- { id: 'n2', type: 'helper' },
243
- ];
244
- helper.load(authenticateSap, flow, () => {
245
- const n2 = helper.getNode('n2');
246
- const n1 = helper.getNode('n1');
247
- n1.credentials.user = 'user';
248
- n1.credentials.password = 'password';
249
- n1.credentials.company = 'company';
250
-
251
- sinon.stub(Support, 'login').resolves({
252
- headers: {
253
- 'Content-Type': 'application/json',
254
- 'Content-Length': 100,
255
- },
256
- });
257
-
258
- n1.context().flow.set(`_YOU_SapServiceLayer_${n1.id}.headers`, true, 'memory1', function (error) {
259
- // console.log(error);
260
- });
261
-
262
- n1.receive({});
263
-
264
- n2.on('input', (msg) => {
265
- try {
266
- msg.should.have.property('_msgid');
267
- done();
268
- } catch (err) {
269
- done(err);
270
- }
271
- });
272
- });
273
- });
274
-
275
- it('should have disconnected', (done) => {
276
- const flow = [
277
- {
278
- id: 'n1',
279
- type: 'authenticateSap',
280
- name: 'authenticateSap',
281
- wires: [['n2']],
282
- z: 'flow',
283
- rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
284
- },
285
- ];
286
- helper.load(authenticateSap, flow, () => {
287
- // const n2 = helper.getNode('n2');
288
- const n1 = helper.getNode('n1');
289
- n1.credentials.user = 'user';
290
- n1.credentials.password = 'password';
291
- n1.credentials.company = 'company';
292
-
293
- sinon.stub(Support, 'login').rejects();
294
-
295
- n1.receive({});
296
-
297
- n1.on('call:error', (error) => {
298
- try {
299
- error.should.have.property('firstArg', new Error('Error'));
300
- done();
301
- } catch (err) {
302
- done(err);
303
- }
304
- });
305
- });
306
- });
307
- });
1
+ const should = require('should');
2
+ const helper = require('node-red-node-test-helper');
3
+ const authenticateSap = require('../nodes/authenticateSap');
4
+ const Context = require('../node_modules/./@node-red/runtime/lib/nodes/context/index');
5
+ const sinon = require('sinon');
6
+ const Support = require('../nodes/support');
7
+
8
+ helper.init(require.resolve('node-red'));
9
+
10
+ describe('authenticateSap Node', () => {
11
+ beforeEach((done) => {
12
+ helper.startServer(done);
13
+ });
14
+
15
+ function initContext(done) {
16
+ Context.init({
17
+ contextStorage: {
18
+ memory0: {
19
+ module: 'memory',
20
+ },
21
+ memory1: {
22
+ module: 'memory',
23
+ },
24
+ },
25
+ });
26
+ Context.load().then(function () {
27
+ done();
28
+ });
29
+ }
30
+
31
+ afterEach((done) => {
32
+ helper
33
+ .unload()
34
+ .then(function () {
35
+ return Context.clean({ allNodes: {} });
36
+ })
37
+ .then(function () {
38
+ return Context.close();
39
+ })
40
+ .then(function () {
41
+ helper.stopServer(done);
42
+ });
43
+
44
+ // Restore the default sandbox here
45
+ sinon.restore();
46
+
47
+ // helper.unload();
48
+ // helper.stopServer(done);
49
+ });
50
+
51
+ it('should be loaded', (done) => {
52
+ const flow = [
53
+ {
54
+ id: 'n1',
55
+ type: 'authenticateSap',
56
+ name: 'authenticateSap',
57
+ wires: [['n2']],
58
+ z: 'flow',
59
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
60
+ },
61
+ ];
62
+
63
+ helper.load(authenticateSap, flow, () => {
64
+ initContext(function () {
65
+ const n1 = helper.getNode('n1');
66
+
67
+ // console.log(helper.log().args);
68
+
69
+ // n1.context().flow.set('A', 1, 'memory1', function (error) {
70
+ // console.log(error);
71
+ // });
72
+
73
+ // console.log(n1.context().flow.get('A', 'memory1'));
74
+ // console.log('- - - B- - - -');
75
+
76
+ // n1.id
77
+ // flow.push({
78
+ // [`_YOU_SapServiceLayer_${n1.id}.headers`]:
79
+ // })
80
+
81
+ try {
82
+ // n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Set credentials1' });
83
+ // should.equal(n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Missing credentials' }), true);
84
+ n1.should.have.property('name', 'authenticateSap');
85
+ done();
86
+ } catch (err) {
87
+ done(err);
88
+ }
89
+ });
90
+ });
91
+ });
92
+
93
+ it('should no have credentials', (done) => {
94
+ const flow = [
95
+ {
96
+ id: 'n1',
97
+ type: 'authenticateSap',
98
+ name: 'authenticateSap',
99
+ wires: [['n2']],
100
+ z: 'flow',
101
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
102
+ },
103
+ ];
104
+ helper.load(authenticateSap, flow, () => {
105
+ initContext(function () {
106
+ const n1 = helper.getNode('n1');
107
+
108
+ try {
109
+ should.equal(n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Missing credentials' }), true);
110
+ n1.should.have.property('name', 'authenticateSap');
111
+ done();
112
+ } catch (err) {
113
+ done(err);
114
+ }
115
+ });
116
+ });
117
+ });
118
+
119
+ it('should no have credentials when send message', (done) => {
120
+ const flow = [
121
+ {
122
+ id: 'n1',
123
+ type: 'authenticateSap',
124
+ name: 'authenticateSap',
125
+ wires: [['n2']],
126
+ z: 'flow',
127
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
128
+ },
129
+ ];
130
+ helper.load(authenticateSap, flow, () => {
131
+ const n1 = helper.getNode('n1');
132
+
133
+ n1.receive({});
134
+
135
+ n1.on('call:error', (error) => {
136
+ try {
137
+ should.equal(n1.status.lastCall.calledWith({ fill: 'red', shape: 'dot', text: 'Missing credentials' }), true);
138
+ error.should.have.property('firstArg', new Error('Missing credentials'));
139
+ done();
140
+ } catch (err) {
141
+ done(err);
142
+ }
143
+ });
144
+ });
145
+ });
146
+
147
+ it('should generic error ', (done) => {
148
+ const flow = [
149
+ {
150
+ id: 'n1',
151
+ type: 'authenticateSap',
152
+ name: 'authenticateSap',
153
+ wires: [['n2']],
154
+ z: 'flow',
155
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
156
+ },
157
+ { id: 'n2', type: 'helper' },
158
+ ];
159
+ helper.load(authenticateSap, flow, () => {
160
+ const n2 = helper.getNode('n2');
161
+ const n1 = helper.getNode('n1');
162
+ n1.credentials.user = 'user';
163
+ n1.credentials.password = 'password';
164
+ n1.credentials.company = 'company';
165
+
166
+ sinon.stub(Support, 'login').rejects(new Error('Custom error'));
167
+
168
+ // n1.context().flow.set(`_YOU_SapServiceLayer_${n1.id}.headers`, true, 'memory1', function (error) {
169
+ // // console.log(error);
170
+ // });
171
+
172
+ n1.receive({});
173
+
174
+ n2.on('input', (msg) => {
175
+ try {
176
+ msg.should.have.property('payload', new Error('Custom error'));
177
+ done();
178
+ } catch (err) {
179
+ done(err);
180
+ }
181
+ });
182
+
183
+ n1.on('call:error', (error) => {
184
+ try {
185
+ error.should.have.property('firstArg', new Error('Custom error'));
186
+ } catch (err) {
187
+ done(err);
188
+ }
189
+ });
190
+ });
191
+ });
192
+
193
+ it('should have without headers connected', (done) => {
194
+ const flow = [
195
+ {
196
+ id: 'n1',
197
+ type: 'authenticateSap',
198
+ name: 'authenticateSap',
199
+ wires: [['n2']],
200
+ z: 'flow',
201
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
202
+ },
203
+ { id: 'n2', type: 'helper' },
204
+ ];
205
+ helper.load(authenticateSap, flow, () => {
206
+ const n2 = helper.getNode('n2');
207
+ const n1 = helper.getNode('n1');
208
+ n1.credentials.user = 'user';
209
+ n1.credentials.password = 'password';
210
+ n1.credentials.company = 'company';
211
+
212
+ sinon.stub(Support, 'login').resolves({
213
+ headers: {
214
+ 'Content-Type': 'application/json',
215
+ 'Content-Length': 100,
216
+ },
217
+ });
218
+
219
+ n1.receive({});
220
+
221
+ n2.on('input', (msg) => {
222
+ try {
223
+ msg.should.have.property('_msgid');
224
+ done();
225
+ } catch (err) {
226
+ done(err);
227
+ }
228
+ });
229
+ });
230
+ });
231
+
232
+ it('should have with headers connected', (done) => {
233
+ const flow = [
234
+ {
235
+ id: 'n1',
236
+ type: 'authenticateSap',
237
+ name: 'authenticateSap',
238
+ wires: [['n2']],
239
+ z: 'flow',
240
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
241
+ },
242
+ { id: 'n2', type: 'helper' },
243
+ ];
244
+ helper.load(authenticateSap, flow, () => {
245
+ const n2 = helper.getNode('n2');
246
+ const n1 = helper.getNode('n1');
247
+ n1.credentials.user = 'user';
248
+ n1.credentials.password = 'password';
249
+ n1.credentials.company = 'company';
250
+
251
+ sinon.stub(Support, 'login').resolves({
252
+ headers: {
253
+ 'Content-Type': 'application/json',
254
+ 'Content-Length': 100,
255
+ },
256
+ });
257
+
258
+ n1.context().flow.set(`_YOU_SapServiceLayer_${n1.id}.headers`, true, 'memory1', function (error) {
259
+ // console.log(error);
260
+ });
261
+
262
+ n1.receive({});
263
+
264
+ n2.on('input', (msg) => {
265
+ try {
266
+ msg.should.have.property('_msgid');
267
+ done();
268
+ } catch (err) {
269
+ done(err);
270
+ }
271
+ });
272
+ });
273
+ });
274
+
275
+ it('should have disconnected', (done) => {
276
+ const flow = [
277
+ {
278
+ id: 'n1',
279
+ type: 'authenticateSap',
280
+ name: 'authenticateSap',
281
+ wires: [['n2']],
282
+ z: 'flow',
283
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
284
+ },
285
+ ];
286
+ helper.load(authenticateSap, flow, () => {
287
+ // const n2 = helper.getNode('n2');
288
+ const n1 = helper.getNode('n1');
289
+ n1.credentials.user = 'user';
290
+ n1.credentials.password = 'password';
291
+ n1.credentials.company = 'company';
292
+
293
+ sinon.stub(Support, 'login').rejects();
294
+
295
+ n1.receive({});
296
+
297
+ n1.on('call:error', (error) => {
298
+ try {
299
+ error.should.have.property('firstArg', new Error('Error'));
300
+ done();
301
+ } catch (err) {
302
+ done(err);
303
+ }
304
+ });
305
+ });
306
+ });
307
+ });