@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,1419 +1,1419 @@
1
- const should = require('should');
2
- const expect = require('chai').expect;
3
- const sinon = require('sinon');
4
- const Support = require('../nodes/support');
5
- // import * as Support from '../nodes/support';
6
-
7
- describe('support library', () => {
8
- // beforeEach((done) => {
9
- // // helper.startServer(done);
10
- // });
11
-
12
- // afterEach(() => {
13
- // // Restore the default sandbox here
14
- // sinon.restore();
15
- // });
16
-
17
- describe('generateRequest() ', () => {
18
- it('should generate a correct request', () => {
19
- const node = {
20
- context: () => {
21
- return {
22
- global: {
23
- get: (param) => {
24
- if (param == '_YOU_SapServiceLayer_1.host') {
25
- return 'host';
26
- }
27
- if (param == '_YOU_SapServiceLayer_1.port') {
28
- return 'port';
29
- }
30
- if (param == '_YOU_SapServiceLayer_1.version') {
31
- return 'version';
32
- }
33
- if (param == '_YOU_SapServiceLayer_1.headers') {
34
- return ['header:1', 'header:2'];
35
- }
36
- },
37
- },
38
- };
39
- },
40
- };
41
-
42
- const msg = {
43
- _YOU_SapServiceLayer: {
44
- idAuth: 1,
45
- },
46
- };
47
- const config = {
48
- entity: 'businessPartner',
49
- query: { select: ['ItemCode', 'ItemName'] },
50
- };
51
- let options = { method: 'GET', hasRawQuery: true };
52
- const expectedValue = {
53
- axiosOptions: {
54
- headers: {
55
- Cookie: 'header:1;header:2',
56
- },
57
- method: 'GET',
58
- rejectUnauthorized: false,
59
- url: 'https://host:port/b1s/version/businessPartner?$select=ItemCode,ItemName',
60
- withCredentials: true,
61
- },
62
- idAuthNode: 1,
63
- };
64
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
65
-
66
- // Headers
67
- const config2 = {
68
- entity: 'businessPartner',
69
- headers: 'myHeaders',
70
- query: { select: ['ItemCode', 'ItemName'] },
71
- };
72
- const msg2 = {
73
- _YOU_SapServiceLayer: {
74
- idAuth: 1,
75
- },
76
- myHeaders: { Prefer: 'odata.maxpagesize=5' },
77
- };
78
- const options2 = { method: 'GET', hasRawQuery: false };
79
- const expectedValue2 = {
80
- axiosOptions: {
81
- headers: {
82
- Cookie: 'header:1;header:2',
83
- Prefer: 'odata.maxpagesize=5',
84
- },
85
- method: 'GET',
86
- rejectUnauthorized: false,
87
- url: 'https://host:port/b1s/version/businessPartner',
88
- withCredentials: true,
89
- },
90
- idAuthNode: 1,
91
- };
92
- should.deepEqual(Support.generateRequest(node, msg2, config2, options2), expectedValue2);
93
- });
94
-
95
- it('should generate a correct request with entityId', () => {
96
- const node = {
97
- context: () => {
98
- return {
99
- global: {
100
- get: (param) => {
101
- if (param == '_YOU_SapServiceLayer_1.host') {
102
- return 'host';
103
- }
104
- if (param == '_YOU_SapServiceLayer_1.port') {
105
- return 'port';
106
- }
107
- if (param == '_YOU_SapServiceLayer_1.version') {
108
- return 'version';
109
- }
110
- if (param == '_YOU_SapServiceLayer_1.headers') {
111
- return ['header:1', 'header:2'];
112
- }
113
- },
114
- },
115
- };
116
- },
117
- };
118
-
119
- const msg = {
120
- _YOU_SapServiceLayer: {
121
- idAuth: 1,
122
- },
123
- entityId: 1,
124
- };
125
- let config = {
126
- entity: 'BusinessPartner',
127
- entityId: 'entityId',
128
- };
129
- const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
130
- const expectedValue = {
131
- axiosOptions: {
132
- headers: {
133
- Cookie: 'header:1;header:2',
134
- },
135
- method: 'GET',
136
- rejectUnauthorized: false,
137
- url: 'https://host:port/b1s/version/BusinessPartner(1)',
138
- withCredentials: true,
139
- },
140
- idAuthNode: 1,
141
- };
142
-
143
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
144
-
145
- config.entity = 'EmailGroups';
146
- const expectedValue1 = {
147
- axiosOptions: {
148
- headers: {
149
- Cookie: 'header:1;header:2',
150
- },
151
- method: 'GET',
152
- rejectUnauthorized: false,
153
- url: `https://host:port/b1s/version/EmailGroups('1')`,
154
- withCredentials: true,
155
- },
156
- idAuthNode: 1,
157
- };
158
-
159
- // thick SAP hack
160
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue1);
161
- });
162
- it('should generate a correct request change HTTP VERB', () => {
163
- const node = {
164
- context: () => {
165
- return {
166
- global: {
167
- get: (param) => {
168
- if (param == '_YOU_SapServiceLayer_1.host') {
169
- return 'host';
170
- }
171
- if (param == '_YOU_SapServiceLayer_1.port') {
172
- return 'port';
173
- }
174
- if (param == '_YOU_SapServiceLayer_1.version') {
175
- return 'version';
176
- }
177
- if (param == '_YOU_SapServiceLayer_1.headers') {
178
- return ['header:1', 'header:2'];
179
- }
180
- },
181
- },
182
- };
183
- },
184
- };
185
-
186
- const msg = {
187
- _YOU_SapServiceLayer: {
188
- idAuth: 1,
189
- },
190
- };
191
- let config = {
192
- entity: 'BusinessPartner',
193
- };
194
- const options = { method: 'POST', hasRawQuery: true, hasEntityId: false };
195
- const expectedValue = {
196
- axiosOptions: {
197
- headers: {
198
- Cookie: 'header:1;header:2',
199
- },
200
- method: 'POST',
201
- rejectUnauthorized: false,
202
- url: 'https://host:port/b1s/version/BusinessPartner',
203
- withCredentials: true,
204
- },
205
- idAuthNode: 1,
206
- };
207
-
208
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
209
- });
210
- it('should generate a correct request with nextLink', () => {
211
- const node = {
212
- context: () => {
213
- return {
214
- global: {
215
- get: (param) => {
216
- if (param == '_YOU_SapServiceLayer_1.host') {
217
- return 'host';
218
- }
219
- if (param == '_YOU_SapServiceLayer_1.port') {
220
- return 'port';
221
- }
222
- if (param == '_YOU_SapServiceLayer_1.version') {
223
- return 'version';
224
- }
225
- if (param == '_YOU_SapServiceLayer_1.headers') {
226
- return ['header:1', 'header:2'];
227
- }
228
- },
229
- },
230
- };
231
- },
232
- };
233
-
234
- const msg = {
235
- _YOU_SapServiceLayer: {
236
- idAuth: 1,
237
- },
238
- nextLink: 'BusinessPartners?$select=CardCode&$skip=50005',
239
- };
240
- const config = {
241
- entity: 'businessPartner',
242
- nextLink: 'nextLink',
243
- query: { select: ['ItemCode', 'ItemName'] },
244
- };
245
- let options = { method: 'GET', hasRawQuery: true };
246
- const expectedValue = {
247
- axiosOptions: {
248
- headers: {
249
- Cookie: 'header:1;header:2',
250
- },
251
- method: 'GET',
252
- rejectUnauthorized: false,
253
- url: 'https://host:port/b1s/version/BusinessPartners?$select=CardCode&$skip=50005',
254
- withCredentials: true,
255
- },
256
- idAuthNode: 1,
257
- };
258
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
259
- });
260
-
261
- it('should generate a correct request Close', () => {
262
- const node = {
263
- context: () => {
264
- return {
265
- global: {
266
- get: (param) => {
267
- if (param == '_YOU_SapServiceLayer_1.host') {
268
- return 'host';
269
- }
270
- if (param == '_YOU_SapServiceLayer_1.port') {
271
- return 'port';
272
- }
273
- if (param == '_YOU_SapServiceLayer_1.version') {
274
- return 'version';
275
- }
276
- if (param == '_YOU_SapServiceLayer_1.headers') {
277
- return ['header:1', 'header:2'];
278
- }
279
- },
280
- },
281
- };
282
- },
283
- };
284
-
285
- const msg = {
286
- _YOU_SapServiceLayer: {
287
- idAuth: 1,
288
- },
289
- entityId: 1,
290
- };
291
- const config = {
292
- entity: 'BusinessPartners',
293
- entityId: 'entityId',
294
- };
295
- let options = { method: 'POST', hasRawQuery: false, isClose: true, hasEntityId: true };
296
- const expectedValue = {
297
- axiosOptions: {
298
- headers: {
299
- Cookie: 'header:1;header:2',
300
- },
301
- method: 'POST',
302
- rejectUnauthorized: false,
303
- url: `https://host:port/b1s/version/BusinessPartners('1')/Close`,
304
- withCredentials: true,
305
- },
306
- idAuthNode: 1,
307
- };
308
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
309
- });
310
-
311
- it('should generate a correct request with UDO', () => {
312
- const node = {
313
- context: () => {
314
- return {
315
- global: {
316
- get: (param) => {
317
- if (param == '_YOU_SapServiceLayer_1.host') {
318
- return 'host';
319
- }
320
- if (param == '_YOU_SapServiceLayer_1.port') {
321
- return 'port';
322
- }
323
- if (param == '_YOU_SapServiceLayer_1.version') {
324
- return 'version';
325
- }
326
- if (param == '_YOU_SapServiceLayer_1.headers') {
327
- return ['header:1', 'header:2'];
328
- }
329
- },
330
- },
331
- };
332
- },
333
- };
334
-
335
- const msg = {
336
- _YOU_SapServiceLayer: {
337
- idAuth: 1,
338
- },
339
- DocEntry: 1,
340
- };
341
- let config = {
342
- entity: 'UDO',
343
- udo: 'YOU_SAP_CUSTOM_ENTITY',
344
- docEntry: 'DocEntry',
345
- };
346
- const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
347
- const expectedValue = {
348
- axiosOptions: {
349
- headers: {
350
- Cookie: 'header:1;header:2',
351
- },
352
- method: 'GET',
353
- rejectUnauthorized: false,
354
- url: 'https://host:port/b1s/version/YOU_SAP_CUSTOM_ENTITY(1)',
355
- withCredentials: true,
356
- },
357
- idAuthNode: 1,
358
- };
359
-
360
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
361
- });
362
-
363
- it('should generate a request without DocEntry (UDO)', () => {
364
- const node = {
365
- context: () => {
366
- return {
367
- global: {
368
- get: (param) => {
369
- if (param == '_YOU_SapServiceLayer_1.host') {
370
- return 'host';
371
- }
372
- if (param == '_YOU_SapServiceLayer_1.port') {
373
- return 'port';
374
- }
375
- if (param == '_YOU_SapServiceLayer_1.version') {
376
- return 'version';
377
- }
378
- if (param == '_YOU_SapServiceLayer_1.headers') {
379
- return ['header:1', 'header:2'];
380
- }
381
- },
382
- },
383
- };
384
- },
385
- };
386
-
387
- const msg = {
388
- _YOU_SapServiceLayer: {
389
- idAuth: 1,
390
- },
391
- };
392
- let config = {
393
- entity: 'UDO',
394
- udo: 'YOU_SAP_CUSTOM_ENTITY',
395
- docEntry: 'docEntry',
396
- };
397
- const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
398
-
399
- expect(() => {
400
- Support.generateRequest(node, msg, config, options);
401
- }).to.throw('Missing docEntry');
402
- });
403
-
404
- it('should generate a correct request with UDT', () => {
405
- const node = {
406
- context: () => {
407
- return {
408
- global: {
409
- get: (param) => {
410
- if (param == '_YOU_SapServiceLayer_1.host') {
411
- return 'host';
412
- }
413
- if (param == '_YOU_SapServiceLayer_1.port') {
414
- return 'port';
415
- }
416
- if (param == '_YOU_SapServiceLayer_1.version') {
417
- return 'version';
418
- }
419
- if (param == '_YOU_SapServiceLayer_1.headers') {
420
- return ['header:1', 'header:2'];
421
- }
422
- },
423
- },
424
- };
425
- },
426
- };
427
-
428
- const msg = {
429
- _YOU_SapServiceLayer: {
430
- idAuth: 1,
431
- },
432
- Code: '0001',
433
- };
434
- let config = {
435
- entity: 'UDT',
436
- udt: 'YOU_SAP_CUSTOM_ENTITY',
437
- code: 'Code',
438
- };
439
- const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
440
- const expectedValue = {
441
- axiosOptions: {
442
- headers: {
443
- Cookie: 'header:1;header:2',
444
- },
445
- method: 'GET',
446
- rejectUnauthorized: false,
447
- url: `https://host:port/b1s/version/YOU_SAP_CUSTOM_ENTITY('0001')`,
448
- withCredentials: true,
449
- },
450
- idAuthNode: 1,
451
- };
452
-
453
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
454
- });
455
-
456
- it('should generate a request without Code (UDT)', () => {
457
- const node = {
458
- context: () => {
459
- return {
460
- global: {
461
- get: (param) => {
462
- if (param == '_YOU_SapServiceLayer_1.host') {
463
- return 'host';
464
- }
465
- if (param == '_YOU_SapServiceLayer_1.port') {
466
- return 'port';
467
- }
468
- if (param == '_YOU_SapServiceLayer_1.version') {
469
- return 'version';
470
- }
471
- if (param == '_YOU_SapServiceLayer_1.headers') {
472
- return ['header:1', 'header:2'];
473
- }
474
- },
475
- },
476
- };
477
- },
478
- };
479
-
480
- const msg = {
481
- _YOU_SapServiceLayer: {
482
- idAuth: 1,
483
- },
484
- };
485
- let config = {
486
- entity: 'UDT',
487
- udt: 'YOU_SAP_CUSTOM_ENTITY',
488
- code: 'Code',
489
- };
490
- const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
491
-
492
- expect(() => {
493
- Support.generateRequest(node, msg, config, options);
494
- }).to.throw('Missing Code');
495
- });
496
-
497
- it('should generate a correct cross join request', () => {
498
- const node = {
499
- context: () => {
500
- return {
501
- global: {
502
- get: (param) => {
503
- if (param == '_YOU_SapServiceLayer_1.host') {
504
- return 'host';
505
- }
506
- if (param == '_YOU_SapServiceLayer_1.port') {
507
- return 'port';
508
- }
509
- if (param == '_YOU_SapServiceLayer_1.version') {
510
- return 'version';
511
- }
512
- if (param == '_YOU_SapServiceLayer_1.headers') {
513
- return ['header:1', 'header:2'];
514
- }
515
- },
516
- },
517
- };
518
- },
519
- };
520
-
521
- const rawQuery = {
522
- expand: {
523
- Orders: { select: ['DocEntry', 'DocNum'] },
524
- BusinessPartners: { select: ['CardCode', 'CardName'] },
525
- },
526
- filter: {
527
- 'Orders/CardCode': { eq: { type: 'raw', value: 'BusinessPartners/CardCode' } },
528
- },
529
- orderBy: ['CardCode desc'],
530
- };
531
-
532
- const msg = {
533
- _YOU_SapServiceLayer: {
534
- idAuth: 1,
535
- },
536
- };
537
- const config = {
538
- entity: 'BusinessPartners,Orders',
539
- query: rawQuery,
540
- };
541
- const options = { method: 'GET', hasRawQuery: true, hasEntityId: false, isCrossJoin: true };
542
- const expectedValue = {
543
- axiosOptions: {
544
- headers: {
545
- Cookie: 'header:1;header:2',
546
- },
547
- method: 'GET',
548
- rejectUnauthorized: false,
549
- url: 'https://host:port/b1s/version/$crossjoin(BusinessPartners,Orders)?$filter=Orders/CardCode eq BusinessPartners/CardCode&$expand=Orders($select=DocEntry,DocNum),BusinessPartners($select=CardCode,CardName)&$orderby=CardCode desc',
550
- withCredentials: true,
551
- },
552
- idAuthNode: 1,
553
- };
554
-
555
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
556
- });
557
-
558
- it('should generate a correct request with Services', () => {
559
- const node = {
560
- context: () => {
561
- return {
562
- global: {
563
- get: (param) => {
564
- if (param == '_YOU_SapServiceLayer_1.host') {
565
- return 'host';
566
- }
567
- if (param == '_YOU_SapServiceLayer_1.port') {
568
- return 'port';
569
- }
570
- if (param == '_YOU_SapServiceLayer_1.version') {
571
- return 'version';
572
- }
573
- if (param == '_YOU_SapServiceLayer_1.headers') {
574
- return ['header:1', 'header:2'];
575
- }
576
- },
577
- },
578
- };
579
- },
580
- };
581
-
582
- const msg = {
583
- _YOU_SapServiceLayer: {
584
- idAuth: 1,
585
- },
586
- DocEntry: 1,
587
- };
588
- let config = {
589
- service: 'ApprovalTemplatesService_GetApprovalTemplateList',
590
- };
591
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isService: true };
592
- const expectedValue = {
593
- axiosOptions: {
594
- headers: {
595
- Cookie: 'header:1;header:2',
596
- },
597
- method: 'POST',
598
- rejectUnauthorized: false,
599
- url: 'https://host:port/b1s/version/ApprovalTemplatesService_GetApprovalTemplateList',
600
- withCredentials: true,
601
- },
602
- idAuthNode: 1,
603
- };
604
-
605
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
606
- });
607
-
608
- it('should generate a error request with Services missing service', () => {
609
- const node = {
610
- context: () => {
611
- return {
612
- global: {
613
- get: (param) => {
614
- if (param == '_YOU_SapServiceLayer_1.host') {
615
- return 'host';
616
- }
617
- if (param == '_YOU_SapServiceLayer_1.port') {
618
- return 'port';
619
- }
620
- if (param == '_YOU_SapServiceLayer_1.version') {
621
- return 'version';
622
- }
623
- if (param == '_YOU_SapServiceLayer_1.headers') {
624
- return ['header:1', 'header:2'];
625
- }
626
- },
627
- },
628
- };
629
- },
630
- };
631
-
632
- const msg = {
633
- _YOU_SapServiceLayer: {
634
- idAuth: 1,
635
- },
636
- DocEntry: 1,
637
- };
638
- let config = {
639
- // service: 'ApprovalTemplatesService_GetApprovalTemplateList',
640
- };
641
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isService: true };
642
- const expectedValue = {
643
- axiosOptions: {
644
- headers: {
645
- Cookie: 'header:1;header:2',
646
- },
647
- method: 'POST',
648
- rejectUnauthorized: false,
649
- url: 'https://host:port/b1s/version/ApprovalTemplatesService_GetApprovalTemplateList',
650
- withCredentials: true,
651
- },
652
- idAuthNode: 1,
653
- };
654
-
655
- expect(() => {
656
- Support.generateRequest(node, msg, config, options);
657
- }).to.throw('Missing service');
658
- });
659
-
660
- it('should generate a correct request with Manipulate Entity', () => {
661
- const node = {
662
- context: () => {
663
- return {
664
- global: {
665
- get: (param) => {
666
- if (param == '_YOU_SapServiceLayer_1.host') {
667
- return 'host';
668
- }
669
- if (param == '_YOU_SapServiceLayer_1.port') {
670
- return 'port';
671
- }
672
- if (param == '_YOU_SapServiceLayer_1.version') {
673
- return 'version';
674
- }
675
- if (param == '_YOU_SapServiceLayer_1.headers') {
676
- return ['header:1', 'header:2'];
677
- }
678
- },
679
- },
680
- };
681
- },
682
- };
683
-
684
- const msg = {
685
- _YOU_SapServiceLayer: {
686
- idAuth: 1,
687
- },
688
- entityId: 3,
689
- };
690
- let config = {
691
- entity: 'PickLists',
692
- entityId: 'entityId',
693
- manipulateMethod: 'GetReleasedAllocation',
694
- };
695
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
696
- const expectedValue = {
697
- axiosOptions: {
698
- headers: {
699
- Cookie: 'header:1;header:2',
700
- },
701
- method: 'POST',
702
- rejectUnauthorized: false,
703
- url: 'https://host:port/b1s/version/PickLists(3)/GetReleasedAllocation',
704
- withCredentials: true,
705
- },
706
- idAuthNode: 1,
707
- };
708
-
709
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
710
- });
711
-
712
- it('should generate an error request with Manipulate Entity missing entity', () => {
713
- const node = {
714
- context: () => {
715
- return {
716
- global: {
717
- get: (param) => {
718
- if (param == '_YOU_SapServiceLayer_1.host') {
719
- return 'host';
720
- }
721
- if (param == '_YOU_SapServiceLayer_1.port') {
722
- return 'port';
723
- }
724
- if (param == '_YOU_SapServiceLayer_1.version') {
725
- return 'version';
726
- }
727
- if (param == '_YOU_SapServiceLayer_1.headers') {
728
- return ['header:1', 'header:2'];
729
- }
730
- },
731
- },
732
- };
733
- },
734
- };
735
-
736
- const msg = {
737
- _YOU_SapServiceLayer: {
738
- idAuth: 1,
739
- },
740
- entityId: 3,
741
- };
742
- let config = {
743
- // entity: 'PickLists',
744
- entityId: 'entityId',
745
- manipulateMethod: 'GetReleasedAllocation',
746
- };
747
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
748
-
749
- expect(() => {
750
- Support.generateRequest(node, msg, config, options);
751
- }).to.throw('Missing entity');
752
- });
753
-
754
- it('should generate an error request with Manipulate Entity missing entity id', () => {
755
- const node = {
756
- context: () => {
757
- return {
758
- global: {
759
- get: (param) => {
760
- if (param == '_YOU_SapServiceLayer_1.host') {
761
- return 'host';
762
- }
763
- if (param == '_YOU_SapServiceLayer_1.port') {
764
- return 'port';
765
- }
766
- if (param == '_YOU_SapServiceLayer_1.version') {
767
- return 'version';
768
- }
769
- if (param == '_YOU_SapServiceLayer_1.headers') {
770
- return ['header:1', 'header:2'];
771
- }
772
- },
773
- },
774
- };
775
- },
776
- };
777
-
778
- const msg = {
779
- _YOU_SapServiceLayer: {
780
- idAuth: 1,
781
- },
782
- entityId: 3,
783
- };
784
- let config = {
785
- entity: 'PickLists',
786
- // entityId: 'entityId',
787
- manipulateMethod: 'GetReleasedAllocation',
788
- };
789
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
790
-
791
- expect(() => {
792
- Support.generateRequest(node, msg, config, options);
793
- }).to.throw('Missing entityId');
794
- });
795
-
796
- it('should generate an error request with Manipulate Entity missing method', () => {
797
- const node = {
798
- context: () => {
799
- return {
800
- global: {
801
- get: (param) => {
802
- if (param == '_YOU_SapServiceLayer_1.host') {
803
- return 'host';
804
- }
805
- if (param == '_YOU_SapServiceLayer_1.port') {
806
- return 'port';
807
- }
808
- if (param == '_YOU_SapServiceLayer_1.version') {
809
- return 'version';
810
- }
811
- if (param == '_YOU_SapServiceLayer_1.headers') {
812
- return ['header:1', 'header:2'];
813
- }
814
- },
815
- },
816
- };
817
- },
818
- };
819
-
820
- const msg = {
821
- _YOU_SapServiceLayer: {
822
- idAuth: 1,
823
- },
824
- entityId: 3,
825
- };
826
- let config = {
827
- entity: 'PickLists',
828
- entityId: 'entityId',
829
- // manipulateMethod: 'GetReleasedAllocation',
830
- };
831
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
832
-
833
- expect(() => {
834
- Support.generateRequest(node, msg, config, options);
835
- }).to.throw('Missing method');
836
- });
837
-
838
- it('should generate a correct request with SQLQuery create query', () => {
839
- const node = {
840
- context: () => {
841
- return {
842
- global: {
843
- get: (param) => {
844
- if (param == '_YOU_SapServiceLayer_1.host') {
845
- return 'host';
846
- }
847
- if (param == '_YOU_SapServiceLayer_1.port') {
848
- return 'port';
849
- }
850
- if (param == '_YOU_SapServiceLayer_1.version') {
851
- return 'version';
852
- }
853
- if (param == '_YOU_SapServiceLayer_1.headers') {
854
- return ['header:1', 'header:2'];
855
- }
856
- },
857
- },
858
- };
859
- },
860
- };
861
-
862
- const msg = {
863
- _YOU_SapServiceLayer: {
864
- idAuth: 1,
865
- },
866
- entityId: 3,
867
- };
868
- let config = {
869
- sqlCode: 'sqlCode',
870
- sqlName: 'sqlName',
871
- sqlText: 'sqlText',
872
- };
873
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isCreateSQLQuery: true };
874
- const expectedValue = {
875
- axiosOptions: {
876
- headers: {
877
- Cookie: 'header:1;header:2',
878
- },
879
- method: 'POST',
880
- rejectUnauthorized: false,
881
- url: 'https://host:port/b1s/version/SQLQueries',
882
- withCredentials: true,
883
- },
884
- idAuthNode: 1,
885
- };
886
-
887
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
888
- });
889
-
890
- it('should generate a correct request with SQLQuery execute query without params', () => {
891
- const node = {
892
- context: () => {
893
- return {
894
- global: {
895
- get: (param) => {
896
- if (param == '_YOU_SapServiceLayer_1.host') {
897
- return 'host';
898
- }
899
- if (param == '_YOU_SapServiceLayer_1.port') {
900
- return 'port';
901
- }
902
- if (param == '_YOU_SapServiceLayer_1.version') {
903
- return 'version';
904
- }
905
- if (param == '_YOU_SapServiceLayer_1.headers') {
906
- return ['header:1', 'header:2'];
907
- }
908
- },
909
- },
910
- };
911
- },
912
- };
913
-
914
- const msg = {
915
- _YOU_SapServiceLayer: {
916
- idAuth: 1,
917
- },
918
- entityId: 3,
919
- sqlCode: 'queryCode',
920
- };
921
- let config = {
922
- sqlCode: 'sqlCode',
923
- };
924
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isSQLQuery: true };
925
- const expectedValue = {
926
- axiosOptions: {
927
- headers: {
928
- Cookie: 'header:1;header:2',
929
- },
930
- method: 'POST',
931
- rejectUnauthorized: false,
932
- url: `https://host:port/b1s/version/SQLQueries('queryCode')/List`,
933
- withCredentials: true,
934
- },
935
- idAuthNode: 1,
936
- };
937
-
938
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
939
- });
940
-
941
- it('should generate a correct request with SQLQuery execute query with params', () => {
942
- const node = {
943
- context: () => {
944
- return {
945
- global: {
946
- get: (param) => {
947
- if (param == '_YOU_SapServiceLayer_1.host') {
948
- return 'host';
949
- }
950
- if (param == '_YOU_SapServiceLayer_1.port') {
951
- return 'port';
952
- }
953
- if (param == '_YOU_SapServiceLayer_1.version') {
954
- return 'version';
955
- }
956
- if (param == '_YOU_SapServiceLayer_1.headers') {
957
- return ['header:1', 'header:2'];
958
- }
959
- },
960
- },
961
- };
962
- },
963
- };
964
-
965
- const msg = {
966
- _YOU_SapServiceLayer: {
967
- idAuth: 1,
968
- },
969
- entityId: 3,
970
- sqlCode: 'queryCode',
971
- };
972
- let config = {
973
- sqlCode: 'sqlCode',
974
- };
975
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isSQLQuery: true };
976
- const expectedValue = {
977
- axiosOptions: {
978
- headers: {
979
- Cookie: 'header:1;header:2',
980
- },
981
- method: 'POST',
982
- rejectUnauthorized: false,
983
- url: `https://host:port/b1s/version/SQLQueries('queryCode')/List`,
984
- withCredentials: true,
985
- },
986
- idAuthNode: 1,
987
- };
988
-
989
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
990
- });
991
-
992
- it('should generate a correct request with SQLQuery execute query with nextLink', () => {
993
- const node = {
994
- context: () => {
995
- return {
996
- global: {
997
- get: (param) => {
998
- if (param == '_YOU_SapServiceLayer_1.host') {
999
- return 'host';
1000
- }
1001
- if (param == '_YOU_SapServiceLayer_1.port') {
1002
- return 'port';
1003
- }
1004
- if (param == '_YOU_SapServiceLayer_1.version') {
1005
- return 'version';
1006
- }
1007
- if (param == '_YOU_SapServiceLayer_1.headers') {
1008
- return ['header:1', 'header:2'];
1009
- }
1010
- },
1011
- },
1012
- };
1013
- },
1014
- };
1015
-
1016
- const msg = {
1017
- _YOU_SapServiceLayer: {
1018
- idAuth: 1,
1019
- },
1020
- entityId: 3,
1021
- sqlCode: 'queryCode',
1022
- };
1023
- let config = {
1024
- sqlCode: 'sqlCode',
1025
- };
1026
- const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isSQLQuery: true };
1027
- const expectedValue = {
1028
- axiosOptions: {
1029
- headers: {
1030
- Cookie: 'header:1;header:2',
1031
- },
1032
- method: 'POST',
1033
- rejectUnauthorized: false,
1034
- url: `https://host:port/b1s/version/SQLQueries('queryCode')/List`,
1035
- withCredentials: true,
1036
- },
1037
- idAuthNode: 1,
1038
- };
1039
-
1040
- should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
1041
- });
1042
-
1043
- it('should have error missing object', () => {
1044
- const node = {
1045
- context: () => {
1046
- return {
1047
- global: {
1048
- get: (param) => {
1049
- if (param == '_YOU_SapServiceLayer_1.host') {
1050
- return 'host';
1051
- }
1052
- if (param == '_YOU_SapServiceLayer_1.port') {
1053
- return 'port';
1054
- }
1055
- if (param == '_YOU_SapServiceLayer_1.version') {
1056
- return 'version';
1057
- }
1058
- if (param == '_YOU_SapServiceLayer_1.headers') {
1059
- return ['header:1', 'header:2'];
1060
- }
1061
- },
1062
- },
1063
- };
1064
- },
1065
- };
1066
-
1067
- const msg = {
1068
- _YOU_SapServiceLayer: {
1069
- idAuth: 1,
1070
- },
1071
- };
1072
- const config = {};
1073
- const options = { method: 'GET', hasRawQuery: true };
1074
-
1075
- expect(() => {
1076
- Support.generateRequest(node, msg, config, options);
1077
- }).to.throw('Missing entity');
1078
- });
1079
-
1080
- it('should have error missing idAuthNode', () => {
1081
- const node = {
1082
- context: () => {
1083
- return {
1084
- global: {
1085
- get: (param) => {},
1086
- },
1087
- };
1088
- },
1089
- };
1090
-
1091
- const msg = {};
1092
- const config = {};
1093
- const options = { method: 'GET', hasRawQuery: true };
1094
-
1095
- expect(() => {
1096
- Support.generateRequest(node, msg, config, options);
1097
- }).to.throw('Authentication failed');
1098
- });
1099
- });
1100
-
1101
- describe('sendRequest()', () => {
1102
- it('should send a correct request', async () => {
1103
- const node = {
1104
- context: () => {
1105
- return {
1106
- global: {
1107
- get: (param) => {
1108
- if (param == '_YOU_SapServiceLayer_1.host') {
1109
- return 'host';
1110
- }
1111
- if (param == '_YOU_SapServiceLayer_1.port') {
1112
- return 'port';
1113
- }
1114
- if (param == '_YOU_SapServiceLayer_1.version') {
1115
- return 'version';
1116
- }
1117
- if (param == '_YOU_SapServiceLayer_1.headers') {
1118
- return ['header:1', 'header:2'];
1119
- }
1120
- },
1121
- },
1122
- };
1123
- },
1124
- };
1125
-
1126
- const login = async () => Promise.resolve();
1127
-
1128
- const msg = {
1129
- _YOU_SapServiceLayer: {
1130
- idAuth: 1,
1131
- },
1132
- };
1133
- const config = {
1134
- entity: 'businessPartner',
1135
- };
1136
- const options = { method: 'GET', hasRawQuery: true };
1137
- const axios = async () => {
1138
- return true;
1139
- };
1140
-
1141
- const actual = await Support.sendRequest({ node, msg, config, login, axios, options });
1142
-
1143
- should.equal(actual, true);
1144
- });
1145
-
1146
- it('should send a request without mandatory arguments', async () => {
1147
- const node = {
1148
- context: () => {
1149
- return {
1150
- global: {
1151
- get: (param) => {
1152
- if (param == '_YOU_SapServiceLayer_1.host') {
1153
- return 'host';
1154
- }
1155
- if (param == '_YOU_SapServiceLayer_1.port') {
1156
- return 'port';
1157
- }
1158
- if (param == '_YOU_SapServiceLayer_1.version') {
1159
- return 'version';
1160
- }
1161
- if (param == '_YOU_SapServiceLayer_1.headers') {
1162
- return ['header:1', 'header:2'];
1163
- }
1164
- },
1165
- },
1166
- };
1167
- },
1168
- };
1169
-
1170
- const msg = {
1171
- _YOU_SapServiceLayer: {
1172
- idAuth: 1,
1173
- },
1174
- };
1175
- const config = {
1176
- entity: 'businessPartner',
1177
- };
1178
- const options = { method: 'GET', hasRawQuery: true };
1179
-
1180
- const expect = new Error(`Missing mandatory params: config,axios,login.`);
1181
- try {
1182
- await Support.sendRequest({ node, msg, options });
1183
- } catch (error) {
1184
- should.deepEqual(error, expect);
1185
- }
1186
- });
1187
-
1188
- it('should send session error', async () => {
1189
- const node = {
1190
- context: () => {
1191
- return {
1192
- global: {
1193
- get: (param) => {
1194
- if (param == '_YOU_SapServiceLayer_1.host') {
1195
- return 'host';
1196
- }
1197
- if (param == '_YOU_SapServiceLayer_1.port') {
1198
- return 'port';
1199
- }
1200
- if (param == '_YOU_SapServiceLayer_1.version') {
1201
- return 'version';
1202
- }
1203
- if (param == '_YOU_SapServiceLayer_1.headers') {
1204
- return ['header:1', 'header:2'];
1205
- }
1206
- },
1207
- set: (param) => {},
1208
- },
1209
- };
1210
- },
1211
- };
1212
-
1213
- const msg = {
1214
- _YOU_SapServiceLayer: {
1215
- idAuth: 1,
1216
- },
1217
- };
1218
- const config = {
1219
- entity: 'businessPartner',
1220
- };
1221
- const options = { method: 'GET', hasRawQuery: true };
1222
-
1223
- const stubLogin = sinon.stub();
1224
- stubLogin.resolves({
1225
- headers: {
1226
- 'Content-Type': 'application/json',
1227
- 'Content-Length': 100,
1228
- 'set-cookie': 'cookie1=1;cookie2',
1229
- },
1230
- });
1231
-
1232
- const axios = sinon.stub();
1233
- axios.onCall(0).returns(
1234
- Promise.reject({
1235
- response: {
1236
- status: 301,
1237
- },
1238
- })
1239
- );
1240
- axios.onCall(1).returns(true);
1241
-
1242
- const actual = await Support.sendRequest({ node, msg, config, login: stubLogin, axios, options });
1243
- should.equal(actual, true);
1244
- });
1245
-
1246
- it('should send a generic error', async () => {
1247
- const node = {
1248
- context: () => {
1249
- return {
1250
- global: {
1251
- get: (param) => {
1252
- if (param == '_YOU_SapServiceLayer_1.host') {
1253
- return 'host';
1254
- }
1255
- if (param == '_YOU_SapServiceLayer_1.port') {
1256
- return 'port';
1257
- }
1258
- if (param == '_YOU_SapServiceLayer_1.version') {
1259
- return 'version';
1260
- }
1261
- if (param == '_YOU_SapServiceLayer_1.headers') {
1262
- return ['header:1', 'header:2'];
1263
- }
1264
- },
1265
- },
1266
- };
1267
- },
1268
- };
1269
-
1270
- const msg = {
1271
- _YOU_SapServiceLayer: {
1272
- idAuth: 1,
1273
- },
1274
- };
1275
- const config = {
1276
- entity: 'businessPartner',
1277
- };
1278
- const options = { method: 'GET', hasRawQuery: true };
1279
- const login = async () => Promise.resolve();
1280
- const axios = async () => {
1281
- return Promise.reject(new Error('Custom error'));
1282
- };
1283
-
1284
- let actual = null;
1285
- try {
1286
- await Support.sendRequest({ node, msg, config, axios, login, options });
1287
- } catch (error) {
1288
- actual = error;
1289
- }
1290
-
1291
- should.deepEqual(actual, new Error('Custom error'));
1292
- });
1293
-
1294
- it('should handle axios response error #1', async () => {
1295
- const node = {
1296
- send: () => {},
1297
- context: () => {
1298
- return {
1299
- global: {
1300
- get: (param) => {
1301
- if (param == '_YOU_SapServiceLayer_1.host') {
1302
- return 'host';
1303
- }
1304
- if (param == '_YOU_SapServiceLayer_1.port') {
1305
- return 'port';
1306
- }
1307
- if (param == '_YOU_SapServiceLayer_1.version') {
1308
- return 'version';
1309
- }
1310
- if (param == '_YOU_SapServiceLayer_1.headers') {
1311
- return ['header:1', 'header:2'];
1312
- }
1313
- },
1314
- },
1315
- };
1316
- },
1317
- };
1318
-
1319
- const msg = {
1320
- _YOU_SapServiceLayer: {
1321
- idAuth: 1,
1322
- },
1323
- };
1324
- const config = {
1325
- entity: 'businessPartner',
1326
- };
1327
- const options = { method: 'GET', hasRawQuery: true };
1328
-
1329
- const axiosError = {
1330
- response: {
1331
- data: 'Custom Error',
1332
- },
1333
- };
1334
-
1335
- const expect = new Error(JSON.stringify(axiosError.response.data));
1336
-
1337
- const login = async () => Promise.resolve({});
1338
- const axios = async () => {
1339
- return Promise.reject(axiosError);
1340
- };
1341
-
1342
- let actual = null;
1343
- try {
1344
- await Support.sendRequest({ node, msg, config, axios, login, options });
1345
- } catch (error) {
1346
- actual = error;
1347
- }
1348
-
1349
- should.deepEqual(actual, expect);
1350
- });
1351
-
1352
- it('should handle axios response error 401 #2', async () => {
1353
- const node = {
1354
- send: () => {},
1355
- context: () => {
1356
- return {
1357
- global: {
1358
- get: (param) => {
1359
- if (param == '_YOU_SapServiceLayer_1.host') {
1360
- return 'host';
1361
- }
1362
- if (param == '_YOU_SapServiceLayer_1.port') {
1363
- return 'port';
1364
- }
1365
- if (param == '_YOU_SapServiceLayer_1.version') {
1366
- return 'version';
1367
- }
1368
- if (param == '_YOU_SapServiceLayer_1.headers') {
1369
- return ['header:1', 'header:2'];
1370
- }
1371
- },
1372
- set: () => {},
1373
- },
1374
- };
1375
- },
1376
- };
1377
-
1378
- const msg = {
1379
- _YOU_SapServiceLayer: {
1380
- idAuth: 1,
1381
- },
1382
- };
1383
- const config = {
1384
- entity: 'businessPartner',
1385
- };
1386
- const options = { method: 'GET', hasRawQuery: true };
1387
-
1388
- const axiosError = {
1389
- response: {
1390
- status: 401,
1391
- data: 'Custom Error',
1392
- },
1393
- };
1394
-
1395
- const expect = new Error(JSON.stringify(axiosError.response.data));
1396
-
1397
- const login = async () =>
1398
- Promise.resolve({
1399
- headers: {
1400
- 'Content-Type': 'application/json',
1401
- 'Content-Length': 100,
1402
- 'set-cookie': 'cookie1=1;cookie2',
1403
- },
1404
- });
1405
- const axios = async () => {
1406
- return Promise.reject(axiosError);
1407
- };
1408
-
1409
- let actual = null;
1410
- try {
1411
- await Support.sendRequest({ node, msg, config, axios, login, options });
1412
- } catch (error) {
1413
- actual = error;
1414
- }
1415
-
1416
- should.deepEqual(actual, expect);
1417
- });
1418
- });
1419
- });
1
+ const should = require('should');
2
+ const expect = require('chai').expect;
3
+ const sinon = require('sinon');
4
+ const Support = require('../nodes/support');
5
+ // import * as Support from '../nodes/support';
6
+
7
+ describe('support library', () => {
8
+ // beforeEach((done) => {
9
+ // // helper.startServer(done);
10
+ // });
11
+
12
+ // afterEach(() => {
13
+ // // Restore the default sandbox here
14
+ // sinon.restore();
15
+ // });
16
+
17
+ describe('generateRequest() ', () => {
18
+ it('should generate a correct request', () => {
19
+ const node = {
20
+ context: () => {
21
+ return {
22
+ global: {
23
+ get: (param) => {
24
+ if (param == '_YOU_SapServiceLayer_1.host') {
25
+ return 'host';
26
+ }
27
+ if (param == '_YOU_SapServiceLayer_1.port') {
28
+ return 'port';
29
+ }
30
+ if (param == '_YOU_SapServiceLayer_1.version') {
31
+ return 'version';
32
+ }
33
+ if (param == '_YOU_SapServiceLayer_1.headers') {
34
+ return ['header:1', 'header:2'];
35
+ }
36
+ },
37
+ },
38
+ };
39
+ },
40
+ };
41
+
42
+ const msg = {
43
+ _YOU_SapServiceLayer: {
44
+ idAuth: 1,
45
+ },
46
+ };
47
+ const config = {
48
+ entity: 'businessPartner',
49
+ query: { select: ['ItemCode', 'ItemName'] },
50
+ };
51
+ let options = { method: 'GET', hasRawQuery: true };
52
+ const expectedValue = {
53
+ axiosOptions: {
54
+ headers: {
55
+ Cookie: 'header:1;header:2',
56
+ },
57
+ method: 'GET',
58
+ rejectUnauthorized: false,
59
+ url: 'https://host:port/b1s/version/businessPartner?$select=ItemCode,ItemName',
60
+ withCredentials: true,
61
+ },
62
+ idAuthNode: 1,
63
+ };
64
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
65
+
66
+ // Headers
67
+ const config2 = {
68
+ entity: 'businessPartner',
69
+ headers: 'myHeaders',
70
+ query: { select: ['ItemCode', 'ItemName'] },
71
+ };
72
+ const msg2 = {
73
+ _YOU_SapServiceLayer: {
74
+ idAuth: 1,
75
+ },
76
+ myHeaders: { Prefer: 'odata.maxpagesize=5' },
77
+ };
78
+ const options2 = { method: 'GET', hasRawQuery: false };
79
+ const expectedValue2 = {
80
+ axiosOptions: {
81
+ headers: {
82
+ Cookie: 'header:1;header:2',
83
+ Prefer: 'odata.maxpagesize=5',
84
+ },
85
+ method: 'GET',
86
+ rejectUnauthorized: false,
87
+ url: 'https://host:port/b1s/version/businessPartner',
88
+ withCredentials: true,
89
+ },
90
+ idAuthNode: 1,
91
+ };
92
+ should.deepEqual(Support.generateRequest(node, msg2, config2, options2), expectedValue2);
93
+ });
94
+
95
+ it('should generate a correct request with entityId', () => {
96
+ const node = {
97
+ context: () => {
98
+ return {
99
+ global: {
100
+ get: (param) => {
101
+ if (param == '_YOU_SapServiceLayer_1.host') {
102
+ return 'host';
103
+ }
104
+ if (param == '_YOU_SapServiceLayer_1.port') {
105
+ return 'port';
106
+ }
107
+ if (param == '_YOU_SapServiceLayer_1.version') {
108
+ return 'version';
109
+ }
110
+ if (param == '_YOU_SapServiceLayer_1.headers') {
111
+ return ['header:1', 'header:2'];
112
+ }
113
+ },
114
+ },
115
+ };
116
+ },
117
+ };
118
+
119
+ const msg = {
120
+ _YOU_SapServiceLayer: {
121
+ idAuth: 1,
122
+ },
123
+ entityId: 1,
124
+ };
125
+ let config = {
126
+ entity: 'BusinessPartner',
127
+ entityId: 'entityId',
128
+ };
129
+ const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
130
+ const expectedValue = {
131
+ axiosOptions: {
132
+ headers: {
133
+ Cookie: 'header:1;header:2',
134
+ },
135
+ method: 'GET',
136
+ rejectUnauthorized: false,
137
+ url: 'https://host:port/b1s/version/BusinessPartner(1)',
138
+ withCredentials: true,
139
+ },
140
+ idAuthNode: 1,
141
+ };
142
+
143
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
144
+
145
+ config.entity = 'EmailGroups';
146
+ const expectedValue1 = {
147
+ axiosOptions: {
148
+ headers: {
149
+ Cookie: 'header:1;header:2',
150
+ },
151
+ method: 'GET',
152
+ rejectUnauthorized: false,
153
+ url: `https://host:port/b1s/version/EmailGroups('1')`,
154
+ withCredentials: true,
155
+ },
156
+ idAuthNode: 1,
157
+ };
158
+
159
+ // thick SAP hack
160
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue1);
161
+ });
162
+ it('should generate a correct request change HTTP VERB', () => {
163
+ const node = {
164
+ context: () => {
165
+ return {
166
+ global: {
167
+ get: (param) => {
168
+ if (param == '_YOU_SapServiceLayer_1.host') {
169
+ return 'host';
170
+ }
171
+ if (param == '_YOU_SapServiceLayer_1.port') {
172
+ return 'port';
173
+ }
174
+ if (param == '_YOU_SapServiceLayer_1.version') {
175
+ return 'version';
176
+ }
177
+ if (param == '_YOU_SapServiceLayer_1.headers') {
178
+ return ['header:1', 'header:2'];
179
+ }
180
+ },
181
+ },
182
+ };
183
+ },
184
+ };
185
+
186
+ const msg = {
187
+ _YOU_SapServiceLayer: {
188
+ idAuth: 1,
189
+ },
190
+ };
191
+ let config = {
192
+ entity: 'BusinessPartner',
193
+ };
194
+ const options = { method: 'POST', hasRawQuery: true, hasEntityId: false };
195
+ const expectedValue = {
196
+ axiosOptions: {
197
+ headers: {
198
+ Cookie: 'header:1;header:2',
199
+ },
200
+ method: 'POST',
201
+ rejectUnauthorized: false,
202
+ url: 'https://host:port/b1s/version/BusinessPartner',
203
+ withCredentials: true,
204
+ },
205
+ idAuthNode: 1,
206
+ };
207
+
208
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
209
+ });
210
+ it('should generate a correct request with nextLink', () => {
211
+ const node = {
212
+ context: () => {
213
+ return {
214
+ global: {
215
+ get: (param) => {
216
+ if (param == '_YOU_SapServiceLayer_1.host') {
217
+ return 'host';
218
+ }
219
+ if (param == '_YOU_SapServiceLayer_1.port') {
220
+ return 'port';
221
+ }
222
+ if (param == '_YOU_SapServiceLayer_1.version') {
223
+ return 'version';
224
+ }
225
+ if (param == '_YOU_SapServiceLayer_1.headers') {
226
+ return ['header:1', 'header:2'];
227
+ }
228
+ },
229
+ },
230
+ };
231
+ },
232
+ };
233
+
234
+ const msg = {
235
+ _YOU_SapServiceLayer: {
236
+ idAuth: 1,
237
+ },
238
+ nextLink: 'BusinessPartners?$select=CardCode&$skip=50005',
239
+ };
240
+ const config = {
241
+ entity: 'businessPartner',
242
+ nextLink: 'nextLink',
243
+ query: { select: ['ItemCode', 'ItemName'] },
244
+ };
245
+ let options = { method: 'GET', hasRawQuery: true };
246
+ const expectedValue = {
247
+ axiosOptions: {
248
+ headers: {
249
+ Cookie: 'header:1;header:2',
250
+ },
251
+ method: 'GET',
252
+ rejectUnauthorized: false,
253
+ url: 'https://host:port/b1s/version/BusinessPartners?$select=CardCode&$skip=50005',
254
+ withCredentials: true,
255
+ },
256
+ idAuthNode: 1,
257
+ };
258
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
259
+ });
260
+
261
+ it('should generate a correct request Close', () => {
262
+ const node = {
263
+ context: () => {
264
+ return {
265
+ global: {
266
+ get: (param) => {
267
+ if (param == '_YOU_SapServiceLayer_1.host') {
268
+ return 'host';
269
+ }
270
+ if (param == '_YOU_SapServiceLayer_1.port') {
271
+ return 'port';
272
+ }
273
+ if (param == '_YOU_SapServiceLayer_1.version') {
274
+ return 'version';
275
+ }
276
+ if (param == '_YOU_SapServiceLayer_1.headers') {
277
+ return ['header:1', 'header:2'];
278
+ }
279
+ },
280
+ },
281
+ };
282
+ },
283
+ };
284
+
285
+ const msg = {
286
+ _YOU_SapServiceLayer: {
287
+ idAuth: 1,
288
+ },
289
+ entityId: 1,
290
+ };
291
+ const config = {
292
+ entity: 'BusinessPartners',
293
+ entityId: 'entityId',
294
+ };
295
+ let options = { method: 'POST', hasRawQuery: false, isClose: true, hasEntityId: true };
296
+ const expectedValue = {
297
+ axiosOptions: {
298
+ headers: {
299
+ Cookie: 'header:1;header:2',
300
+ },
301
+ method: 'POST',
302
+ rejectUnauthorized: false,
303
+ url: `https://host:port/b1s/version/BusinessPartners('1')/Close`,
304
+ withCredentials: true,
305
+ },
306
+ idAuthNode: 1,
307
+ };
308
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
309
+ });
310
+
311
+ it('should generate a correct request with UDO', () => {
312
+ const node = {
313
+ context: () => {
314
+ return {
315
+ global: {
316
+ get: (param) => {
317
+ if (param == '_YOU_SapServiceLayer_1.host') {
318
+ return 'host';
319
+ }
320
+ if (param == '_YOU_SapServiceLayer_1.port') {
321
+ return 'port';
322
+ }
323
+ if (param == '_YOU_SapServiceLayer_1.version') {
324
+ return 'version';
325
+ }
326
+ if (param == '_YOU_SapServiceLayer_1.headers') {
327
+ return ['header:1', 'header:2'];
328
+ }
329
+ },
330
+ },
331
+ };
332
+ },
333
+ };
334
+
335
+ const msg = {
336
+ _YOU_SapServiceLayer: {
337
+ idAuth: 1,
338
+ },
339
+ DocEntry: 1,
340
+ };
341
+ let config = {
342
+ entity: 'UDO',
343
+ udo: 'YOU_SAP_CUSTOM_ENTITY',
344
+ docEntry: 'DocEntry',
345
+ };
346
+ const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
347
+ const expectedValue = {
348
+ axiosOptions: {
349
+ headers: {
350
+ Cookie: 'header:1;header:2',
351
+ },
352
+ method: 'GET',
353
+ rejectUnauthorized: false,
354
+ url: 'https://host:port/b1s/version/YOU_SAP_CUSTOM_ENTITY(1)',
355
+ withCredentials: true,
356
+ },
357
+ idAuthNode: 1,
358
+ };
359
+
360
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
361
+ });
362
+
363
+ it('should generate a request without DocEntry (UDO)', () => {
364
+ const node = {
365
+ context: () => {
366
+ return {
367
+ global: {
368
+ get: (param) => {
369
+ if (param == '_YOU_SapServiceLayer_1.host') {
370
+ return 'host';
371
+ }
372
+ if (param == '_YOU_SapServiceLayer_1.port') {
373
+ return 'port';
374
+ }
375
+ if (param == '_YOU_SapServiceLayer_1.version') {
376
+ return 'version';
377
+ }
378
+ if (param == '_YOU_SapServiceLayer_1.headers') {
379
+ return ['header:1', 'header:2'];
380
+ }
381
+ },
382
+ },
383
+ };
384
+ },
385
+ };
386
+
387
+ const msg = {
388
+ _YOU_SapServiceLayer: {
389
+ idAuth: 1,
390
+ },
391
+ };
392
+ let config = {
393
+ entity: 'UDO',
394
+ udo: 'YOU_SAP_CUSTOM_ENTITY',
395
+ docEntry: 'docEntry',
396
+ };
397
+ const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
398
+
399
+ expect(() => {
400
+ Support.generateRequest(node, msg, config, options);
401
+ }).to.throw('Missing docEntry');
402
+ });
403
+
404
+ it('should generate a correct request with UDT', () => {
405
+ const node = {
406
+ context: () => {
407
+ return {
408
+ global: {
409
+ get: (param) => {
410
+ if (param == '_YOU_SapServiceLayer_1.host') {
411
+ return 'host';
412
+ }
413
+ if (param == '_YOU_SapServiceLayer_1.port') {
414
+ return 'port';
415
+ }
416
+ if (param == '_YOU_SapServiceLayer_1.version') {
417
+ return 'version';
418
+ }
419
+ if (param == '_YOU_SapServiceLayer_1.headers') {
420
+ return ['header:1', 'header:2'];
421
+ }
422
+ },
423
+ },
424
+ };
425
+ },
426
+ };
427
+
428
+ const msg = {
429
+ _YOU_SapServiceLayer: {
430
+ idAuth: 1,
431
+ },
432
+ Code: '0001',
433
+ };
434
+ let config = {
435
+ entity: 'UDT',
436
+ udt: 'YOU_SAP_CUSTOM_ENTITY',
437
+ code: 'Code',
438
+ };
439
+ const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
440
+ const expectedValue = {
441
+ axiosOptions: {
442
+ headers: {
443
+ Cookie: 'header:1;header:2',
444
+ },
445
+ method: 'GET',
446
+ rejectUnauthorized: false,
447
+ url: `https://host:port/b1s/version/YOU_SAP_CUSTOM_ENTITY('0001')`,
448
+ withCredentials: true,
449
+ },
450
+ idAuthNode: 1,
451
+ };
452
+
453
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
454
+ });
455
+
456
+ it('should generate a request without Code (UDT)', () => {
457
+ const node = {
458
+ context: () => {
459
+ return {
460
+ global: {
461
+ get: (param) => {
462
+ if (param == '_YOU_SapServiceLayer_1.host') {
463
+ return 'host';
464
+ }
465
+ if (param == '_YOU_SapServiceLayer_1.port') {
466
+ return 'port';
467
+ }
468
+ if (param == '_YOU_SapServiceLayer_1.version') {
469
+ return 'version';
470
+ }
471
+ if (param == '_YOU_SapServiceLayer_1.headers') {
472
+ return ['header:1', 'header:2'];
473
+ }
474
+ },
475
+ },
476
+ };
477
+ },
478
+ };
479
+
480
+ const msg = {
481
+ _YOU_SapServiceLayer: {
482
+ idAuth: 1,
483
+ },
484
+ };
485
+ let config = {
486
+ entity: 'UDT',
487
+ udt: 'YOU_SAP_CUSTOM_ENTITY',
488
+ code: 'Code',
489
+ };
490
+ const options = { method: 'GET', hasRawQuery: true, hasEntityId: true };
491
+
492
+ expect(() => {
493
+ Support.generateRequest(node, msg, config, options);
494
+ }).to.throw('Missing Code');
495
+ });
496
+
497
+ it('should generate a correct cross join request', () => {
498
+ const node = {
499
+ context: () => {
500
+ return {
501
+ global: {
502
+ get: (param) => {
503
+ if (param == '_YOU_SapServiceLayer_1.host') {
504
+ return 'host';
505
+ }
506
+ if (param == '_YOU_SapServiceLayer_1.port') {
507
+ return 'port';
508
+ }
509
+ if (param == '_YOU_SapServiceLayer_1.version') {
510
+ return 'version';
511
+ }
512
+ if (param == '_YOU_SapServiceLayer_1.headers') {
513
+ return ['header:1', 'header:2'];
514
+ }
515
+ },
516
+ },
517
+ };
518
+ },
519
+ };
520
+
521
+ const rawQuery = {
522
+ expand: {
523
+ Orders: { select: ['DocEntry', 'DocNum'] },
524
+ BusinessPartners: { select: ['CardCode', 'CardName'] },
525
+ },
526
+ filter: {
527
+ 'Orders/CardCode': { eq: { type: 'raw', value: 'BusinessPartners/CardCode' } },
528
+ },
529
+ orderBy: ['CardCode desc'],
530
+ };
531
+
532
+ const msg = {
533
+ _YOU_SapServiceLayer: {
534
+ idAuth: 1,
535
+ },
536
+ };
537
+ const config = {
538
+ entity: 'BusinessPartners,Orders',
539
+ query: rawQuery,
540
+ };
541
+ const options = { method: 'GET', hasRawQuery: true, hasEntityId: false, isCrossJoin: true };
542
+ const expectedValue = {
543
+ axiosOptions: {
544
+ headers: {
545
+ Cookie: 'header:1;header:2',
546
+ },
547
+ method: 'GET',
548
+ rejectUnauthorized: false,
549
+ url: 'https://host:port/b1s/version/$crossjoin(BusinessPartners,Orders)?$filter=Orders/CardCode eq BusinessPartners/CardCode&$expand=Orders($select=DocEntry,DocNum),BusinessPartners($select=CardCode,CardName)&$orderby=CardCode desc',
550
+ withCredentials: true,
551
+ },
552
+ idAuthNode: 1,
553
+ };
554
+
555
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
556
+ });
557
+
558
+ it('should generate a correct request with Services', () => {
559
+ const node = {
560
+ context: () => {
561
+ return {
562
+ global: {
563
+ get: (param) => {
564
+ if (param == '_YOU_SapServiceLayer_1.host') {
565
+ return 'host';
566
+ }
567
+ if (param == '_YOU_SapServiceLayer_1.port') {
568
+ return 'port';
569
+ }
570
+ if (param == '_YOU_SapServiceLayer_1.version') {
571
+ return 'version';
572
+ }
573
+ if (param == '_YOU_SapServiceLayer_1.headers') {
574
+ return ['header:1', 'header:2'];
575
+ }
576
+ },
577
+ },
578
+ };
579
+ },
580
+ };
581
+
582
+ const msg = {
583
+ _YOU_SapServiceLayer: {
584
+ idAuth: 1,
585
+ },
586
+ DocEntry: 1,
587
+ };
588
+ let config = {
589
+ service: 'ApprovalTemplatesService_GetApprovalTemplateList',
590
+ };
591
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isService: true };
592
+ const expectedValue = {
593
+ axiosOptions: {
594
+ headers: {
595
+ Cookie: 'header:1;header:2',
596
+ },
597
+ method: 'POST',
598
+ rejectUnauthorized: false,
599
+ url: 'https://host:port/b1s/version/ApprovalTemplatesService_GetApprovalTemplateList',
600
+ withCredentials: true,
601
+ },
602
+ idAuthNode: 1,
603
+ };
604
+
605
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
606
+ });
607
+
608
+ it('should generate a error request with Services missing service', () => {
609
+ const node = {
610
+ context: () => {
611
+ return {
612
+ global: {
613
+ get: (param) => {
614
+ if (param == '_YOU_SapServiceLayer_1.host') {
615
+ return 'host';
616
+ }
617
+ if (param == '_YOU_SapServiceLayer_1.port') {
618
+ return 'port';
619
+ }
620
+ if (param == '_YOU_SapServiceLayer_1.version') {
621
+ return 'version';
622
+ }
623
+ if (param == '_YOU_SapServiceLayer_1.headers') {
624
+ return ['header:1', 'header:2'];
625
+ }
626
+ },
627
+ },
628
+ };
629
+ },
630
+ };
631
+
632
+ const msg = {
633
+ _YOU_SapServiceLayer: {
634
+ idAuth: 1,
635
+ },
636
+ DocEntry: 1,
637
+ };
638
+ let config = {
639
+ // service: 'ApprovalTemplatesService_GetApprovalTemplateList',
640
+ };
641
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isService: true };
642
+ const expectedValue = {
643
+ axiosOptions: {
644
+ headers: {
645
+ Cookie: 'header:1;header:2',
646
+ },
647
+ method: 'POST',
648
+ rejectUnauthorized: false,
649
+ url: 'https://host:port/b1s/version/ApprovalTemplatesService_GetApprovalTemplateList',
650
+ withCredentials: true,
651
+ },
652
+ idAuthNode: 1,
653
+ };
654
+
655
+ expect(() => {
656
+ Support.generateRequest(node, msg, config, options);
657
+ }).to.throw('Missing service');
658
+ });
659
+
660
+ it('should generate a correct request with Manipulate Entity', () => {
661
+ const node = {
662
+ context: () => {
663
+ return {
664
+ global: {
665
+ get: (param) => {
666
+ if (param == '_YOU_SapServiceLayer_1.host') {
667
+ return 'host';
668
+ }
669
+ if (param == '_YOU_SapServiceLayer_1.port') {
670
+ return 'port';
671
+ }
672
+ if (param == '_YOU_SapServiceLayer_1.version') {
673
+ return 'version';
674
+ }
675
+ if (param == '_YOU_SapServiceLayer_1.headers') {
676
+ return ['header:1', 'header:2'];
677
+ }
678
+ },
679
+ },
680
+ };
681
+ },
682
+ };
683
+
684
+ const msg = {
685
+ _YOU_SapServiceLayer: {
686
+ idAuth: 1,
687
+ },
688
+ entityId: 3,
689
+ };
690
+ let config = {
691
+ entity: 'PickLists',
692
+ entityId: 'entityId',
693
+ manipulateMethod: 'GetReleasedAllocation',
694
+ };
695
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
696
+ const expectedValue = {
697
+ axiosOptions: {
698
+ headers: {
699
+ Cookie: 'header:1;header:2',
700
+ },
701
+ method: 'POST',
702
+ rejectUnauthorized: false,
703
+ url: 'https://host:port/b1s/version/PickLists(3)/GetReleasedAllocation',
704
+ withCredentials: true,
705
+ },
706
+ idAuthNode: 1,
707
+ };
708
+
709
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
710
+ });
711
+
712
+ it('should generate an error request with Manipulate Entity missing entity', () => {
713
+ const node = {
714
+ context: () => {
715
+ return {
716
+ global: {
717
+ get: (param) => {
718
+ if (param == '_YOU_SapServiceLayer_1.host') {
719
+ return 'host';
720
+ }
721
+ if (param == '_YOU_SapServiceLayer_1.port') {
722
+ return 'port';
723
+ }
724
+ if (param == '_YOU_SapServiceLayer_1.version') {
725
+ return 'version';
726
+ }
727
+ if (param == '_YOU_SapServiceLayer_1.headers') {
728
+ return ['header:1', 'header:2'];
729
+ }
730
+ },
731
+ },
732
+ };
733
+ },
734
+ };
735
+
736
+ const msg = {
737
+ _YOU_SapServiceLayer: {
738
+ idAuth: 1,
739
+ },
740
+ entityId: 3,
741
+ };
742
+ let config = {
743
+ // entity: 'PickLists',
744
+ entityId: 'entityId',
745
+ manipulateMethod: 'GetReleasedAllocation',
746
+ };
747
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
748
+
749
+ expect(() => {
750
+ Support.generateRequest(node, msg, config, options);
751
+ }).to.throw('Missing entity');
752
+ });
753
+
754
+ it('should generate an error request with Manipulate Entity missing entity id', () => {
755
+ const node = {
756
+ context: () => {
757
+ return {
758
+ global: {
759
+ get: (param) => {
760
+ if (param == '_YOU_SapServiceLayer_1.host') {
761
+ return 'host';
762
+ }
763
+ if (param == '_YOU_SapServiceLayer_1.port') {
764
+ return 'port';
765
+ }
766
+ if (param == '_YOU_SapServiceLayer_1.version') {
767
+ return 'version';
768
+ }
769
+ if (param == '_YOU_SapServiceLayer_1.headers') {
770
+ return ['header:1', 'header:2'];
771
+ }
772
+ },
773
+ },
774
+ };
775
+ },
776
+ };
777
+
778
+ const msg = {
779
+ _YOU_SapServiceLayer: {
780
+ idAuth: 1,
781
+ },
782
+ entityId: 3,
783
+ };
784
+ let config = {
785
+ entity: 'PickLists',
786
+ // entityId: 'entityId',
787
+ manipulateMethod: 'GetReleasedAllocation',
788
+ };
789
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
790
+
791
+ expect(() => {
792
+ Support.generateRequest(node, msg, config, options);
793
+ }).to.throw('Missing entityId');
794
+ });
795
+
796
+ it('should generate an error request with Manipulate Entity missing method', () => {
797
+ const node = {
798
+ context: () => {
799
+ return {
800
+ global: {
801
+ get: (param) => {
802
+ if (param == '_YOU_SapServiceLayer_1.host') {
803
+ return 'host';
804
+ }
805
+ if (param == '_YOU_SapServiceLayer_1.port') {
806
+ return 'port';
807
+ }
808
+ if (param == '_YOU_SapServiceLayer_1.version') {
809
+ return 'version';
810
+ }
811
+ if (param == '_YOU_SapServiceLayer_1.headers') {
812
+ return ['header:1', 'header:2'];
813
+ }
814
+ },
815
+ },
816
+ };
817
+ },
818
+ };
819
+
820
+ const msg = {
821
+ _YOU_SapServiceLayer: {
822
+ idAuth: 1,
823
+ },
824
+ entityId: 3,
825
+ };
826
+ let config = {
827
+ entity: 'PickLists',
828
+ entityId: 'entityId',
829
+ // manipulateMethod: 'GetReleasedAllocation',
830
+ };
831
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: true, isManipulate: true };
832
+
833
+ expect(() => {
834
+ Support.generateRequest(node, msg, config, options);
835
+ }).to.throw('Missing method');
836
+ });
837
+
838
+ it('should generate a correct request with SQLQuery create query', () => {
839
+ const node = {
840
+ context: () => {
841
+ return {
842
+ global: {
843
+ get: (param) => {
844
+ if (param == '_YOU_SapServiceLayer_1.host') {
845
+ return 'host';
846
+ }
847
+ if (param == '_YOU_SapServiceLayer_1.port') {
848
+ return 'port';
849
+ }
850
+ if (param == '_YOU_SapServiceLayer_1.version') {
851
+ return 'version';
852
+ }
853
+ if (param == '_YOU_SapServiceLayer_1.headers') {
854
+ return ['header:1', 'header:2'];
855
+ }
856
+ },
857
+ },
858
+ };
859
+ },
860
+ };
861
+
862
+ const msg = {
863
+ _YOU_SapServiceLayer: {
864
+ idAuth: 1,
865
+ },
866
+ entityId: 3,
867
+ };
868
+ let config = {
869
+ sqlCode: 'sqlCode',
870
+ sqlName: 'sqlName',
871
+ sqlText: 'sqlText',
872
+ };
873
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isCreateSQLQuery: true };
874
+ const expectedValue = {
875
+ axiosOptions: {
876
+ headers: {
877
+ Cookie: 'header:1;header:2',
878
+ },
879
+ method: 'POST',
880
+ rejectUnauthorized: false,
881
+ url: 'https://host:port/b1s/version/SQLQueries',
882
+ withCredentials: true,
883
+ },
884
+ idAuthNode: 1,
885
+ };
886
+
887
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
888
+ });
889
+
890
+ it('should generate a correct request with SQLQuery execute query without params', () => {
891
+ const node = {
892
+ context: () => {
893
+ return {
894
+ global: {
895
+ get: (param) => {
896
+ if (param == '_YOU_SapServiceLayer_1.host') {
897
+ return 'host';
898
+ }
899
+ if (param == '_YOU_SapServiceLayer_1.port') {
900
+ return 'port';
901
+ }
902
+ if (param == '_YOU_SapServiceLayer_1.version') {
903
+ return 'version';
904
+ }
905
+ if (param == '_YOU_SapServiceLayer_1.headers') {
906
+ return ['header:1', 'header:2'];
907
+ }
908
+ },
909
+ },
910
+ };
911
+ },
912
+ };
913
+
914
+ const msg = {
915
+ _YOU_SapServiceLayer: {
916
+ idAuth: 1,
917
+ },
918
+ entityId: 3,
919
+ sqlCode: 'queryCode',
920
+ };
921
+ let config = {
922
+ sqlCode: 'sqlCode',
923
+ };
924
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isSQLQuery: true };
925
+ const expectedValue = {
926
+ axiosOptions: {
927
+ headers: {
928
+ Cookie: 'header:1;header:2',
929
+ },
930
+ method: 'POST',
931
+ rejectUnauthorized: false,
932
+ url: `https://host:port/b1s/version/SQLQueries('queryCode')/List`,
933
+ withCredentials: true,
934
+ },
935
+ idAuthNode: 1,
936
+ };
937
+
938
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
939
+ });
940
+
941
+ it('should generate a correct request with SQLQuery execute query with params', () => {
942
+ const node = {
943
+ context: () => {
944
+ return {
945
+ global: {
946
+ get: (param) => {
947
+ if (param == '_YOU_SapServiceLayer_1.host') {
948
+ return 'host';
949
+ }
950
+ if (param == '_YOU_SapServiceLayer_1.port') {
951
+ return 'port';
952
+ }
953
+ if (param == '_YOU_SapServiceLayer_1.version') {
954
+ return 'version';
955
+ }
956
+ if (param == '_YOU_SapServiceLayer_1.headers') {
957
+ return ['header:1', 'header:2'];
958
+ }
959
+ },
960
+ },
961
+ };
962
+ },
963
+ };
964
+
965
+ const msg = {
966
+ _YOU_SapServiceLayer: {
967
+ idAuth: 1,
968
+ },
969
+ entityId: 3,
970
+ sqlCode: 'queryCode',
971
+ };
972
+ let config = {
973
+ sqlCode: 'sqlCode',
974
+ };
975
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isSQLQuery: true };
976
+ const expectedValue = {
977
+ axiosOptions: {
978
+ headers: {
979
+ Cookie: 'header:1;header:2',
980
+ },
981
+ method: 'POST',
982
+ rejectUnauthorized: false,
983
+ url: `https://host:port/b1s/version/SQLQueries('queryCode')/List`,
984
+ withCredentials: true,
985
+ },
986
+ idAuthNode: 1,
987
+ };
988
+
989
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
990
+ });
991
+
992
+ it('should generate a correct request with SQLQuery execute query with nextLink', () => {
993
+ const node = {
994
+ context: () => {
995
+ return {
996
+ global: {
997
+ get: (param) => {
998
+ if (param == '_YOU_SapServiceLayer_1.host') {
999
+ return 'host';
1000
+ }
1001
+ if (param == '_YOU_SapServiceLayer_1.port') {
1002
+ return 'port';
1003
+ }
1004
+ if (param == '_YOU_SapServiceLayer_1.version') {
1005
+ return 'version';
1006
+ }
1007
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1008
+ return ['header:1', 'header:2'];
1009
+ }
1010
+ },
1011
+ },
1012
+ };
1013
+ },
1014
+ };
1015
+
1016
+ const msg = {
1017
+ _YOU_SapServiceLayer: {
1018
+ idAuth: 1,
1019
+ },
1020
+ entityId: 3,
1021
+ sqlCode: 'queryCode',
1022
+ };
1023
+ let config = {
1024
+ sqlCode: 'sqlCode',
1025
+ };
1026
+ const options = { method: 'POST', hasRawQuery: false, hasEntityId: false, isSQLQuery: true };
1027
+ const expectedValue = {
1028
+ axiosOptions: {
1029
+ headers: {
1030
+ Cookie: 'header:1;header:2',
1031
+ },
1032
+ method: 'POST',
1033
+ rejectUnauthorized: false,
1034
+ url: `https://host:port/b1s/version/SQLQueries('queryCode')/List`,
1035
+ withCredentials: true,
1036
+ },
1037
+ idAuthNode: 1,
1038
+ };
1039
+
1040
+ should.deepEqual(Support.generateRequest(node, msg, config, options), expectedValue);
1041
+ });
1042
+
1043
+ it('should have error missing object', () => {
1044
+ const node = {
1045
+ context: () => {
1046
+ return {
1047
+ global: {
1048
+ get: (param) => {
1049
+ if (param == '_YOU_SapServiceLayer_1.host') {
1050
+ return 'host';
1051
+ }
1052
+ if (param == '_YOU_SapServiceLayer_1.port') {
1053
+ return 'port';
1054
+ }
1055
+ if (param == '_YOU_SapServiceLayer_1.version') {
1056
+ return 'version';
1057
+ }
1058
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1059
+ return ['header:1', 'header:2'];
1060
+ }
1061
+ },
1062
+ },
1063
+ };
1064
+ },
1065
+ };
1066
+
1067
+ const msg = {
1068
+ _YOU_SapServiceLayer: {
1069
+ idAuth: 1,
1070
+ },
1071
+ };
1072
+ const config = {};
1073
+ const options = { method: 'GET', hasRawQuery: true };
1074
+
1075
+ expect(() => {
1076
+ Support.generateRequest(node, msg, config, options);
1077
+ }).to.throw('Missing entity');
1078
+ });
1079
+
1080
+ it('should have error missing idAuthNode', () => {
1081
+ const node = {
1082
+ context: () => {
1083
+ return {
1084
+ global: {
1085
+ get: (param) => {},
1086
+ },
1087
+ };
1088
+ },
1089
+ };
1090
+
1091
+ const msg = {};
1092
+ const config = {};
1093
+ const options = { method: 'GET', hasRawQuery: true };
1094
+
1095
+ expect(() => {
1096
+ Support.generateRequest(node, msg, config, options);
1097
+ }).to.throw('Authentication failed');
1098
+ });
1099
+ });
1100
+
1101
+ describe('sendRequest()', () => {
1102
+ it('should send a correct request', async () => {
1103
+ const node = {
1104
+ context: () => {
1105
+ return {
1106
+ global: {
1107
+ get: (param) => {
1108
+ if (param == '_YOU_SapServiceLayer_1.host') {
1109
+ return 'host';
1110
+ }
1111
+ if (param == '_YOU_SapServiceLayer_1.port') {
1112
+ return 'port';
1113
+ }
1114
+ if (param == '_YOU_SapServiceLayer_1.version') {
1115
+ return 'version';
1116
+ }
1117
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1118
+ return ['header:1', 'header:2'];
1119
+ }
1120
+ },
1121
+ },
1122
+ };
1123
+ },
1124
+ };
1125
+
1126
+ const login = async () => Promise.resolve();
1127
+
1128
+ const msg = {
1129
+ _YOU_SapServiceLayer: {
1130
+ idAuth: 1,
1131
+ },
1132
+ };
1133
+ const config = {
1134
+ entity: 'businessPartner',
1135
+ };
1136
+ const options = { method: 'GET', hasRawQuery: true };
1137
+ const axios = async () => {
1138
+ return true;
1139
+ };
1140
+
1141
+ const actual = await Support.sendRequest({ node, msg, config, login, axios, options });
1142
+
1143
+ should.equal(actual, true);
1144
+ });
1145
+
1146
+ it('should send a request without mandatory arguments', async () => {
1147
+ const node = {
1148
+ context: () => {
1149
+ return {
1150
+ global: {
1151
+ get: (param) => {
1152
+ if (param == '_YOU_SapServiceLayer_1.host') {
1153
+ return 'host';
1154
+ }
1155
+ if (param == '_YOU_SapServiceLayer_1.port') {
1156
+ return 'port';
1157
+ }
1158
+ if (param == '_YOU_SapServiceLayer_1.version') {
1159
+ return 'version';
1160
+ }
1161
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1162
+ return ['header:1', 'header:2'];
1163
+ }
1164
+ },
1165
+ },
1166
+ };
1167
+ },
1168
+ };
1169
+
1170
+ const msg = {
1171
+ _YOU_SapServiceLayer: {
1172
+ idAuth: 1,
1173
+ },
1174
+ };
1175
+ const config = {
1176
+ entity: 'businessPartner',
1177
+ };
1178
+ const options = { method: 'GET', hasRawQuery: true };
1179
+
1180
+ const expect = new Error(`Missing mandatory params: config,axios,login.`);
1181
+ try {
1182
+ await Support.sendRequest({ node, msg, options });
1183
+ } catch (error) {
1184
+ should.deepEqual(error, expect);
1185
+ }
1186
+ });
1187
+
1188
+ it('should send session error', async () => {
1189
+ const node = {
1190
+ context: () => {
1191
+ return {
1192
+ global: {
1193
+ get: (param) => {
1194
+ if (param == '_YOU_SapServiceLayer_1.host') {
1195
+ return 'host';
1196
+ }
1197
+ if (param == '_YOU_SapServiceLayer_1.port') {
1198
+ return 'port';
1199
+ }
1200
+ if (param == '_YOU_SapServiceLayer_1.version') {
1201
+ return 'version';
1202
+ }
1203
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1204
+ return ['header:1', 'header:2'];
1205
+ }
1206
+ },
1207
+ set: (param) => {},
1208
+ },
1209
+ };
1210
+ },
1211
+ };
1212
+
1213
+ const msg = {
1214
+ _YOU_SapServiceLayer: {
1215
+ idAuth: 1,
1216
+ },
1217
+ };
1218
+ const config = {
1219
+ entity: 'businessPartner',
1220
+ };
1221
+ const options = { method: 'GET', hasRawQuery: true };
1222
+
1223
+ const stubLogin = sinon.stub();
1224
+ stubLogin.resolves({
1225
+ headers: {
1226
+ 'Content-Type': 'application/json',
1227
+ 'Content-Length': 100,
1228
+ 'set-cookie': 'cookie1=1;cookie2',
1229
+ },
1230
+ });
1231
+
1232
+ const axios = sinon.stub();
1233
+ axios.onCall(0).returns(
1234
+ Promise.reject({
1235
+ response: {
1236
+ status: 301,
1237
+ },
1238
+ })
1239
+ );
1240
+ axios.onCall(1).returns(true);
1241
+
1242
+ const actual = await Support.sendRequest({ node, msg, config, login: stubLogin, axios, options });
1243
+ should.equal(actual, true);
1244
+ });
1245
+
1246
+ it('should send a generic error', async () => {
1247
+ const node = {
1248
+ context: () => {
1249
+ return {
1250
+ global: {
1251
+ get: (param) => {
1252
+ if (param == '_YOU_SapServiceLayer_1.host') {
1253
+ return 'host';
1254
+ }
1255
+ if (param == '_YOU_SapServiceLayer_1.port') {
1256
+ return 'port';
1257
+ }
1258
+ if (param == '_YOU_SapServiceLayer_1.version') {
1259
+ return 'version';
1260
+ }
1261
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1262
+ return ['header:1', 'header:2'];
1263
+ }
1264
+ },
1265
+ },
1266
+ };
1267
+ },
1268
+ };
1269
+
1270
+ const msg = {
1271
+ _YOU_SapServiceLayer: {
1272
+ idAuth: 1,
1273
+ },
1274
+ };
1275
+ const config = {
1276
+ entity: 'businessPartner',
1277
+ };
1278
+ const options = { method: 'GET', hasRawQuery: true };
1279
+ const login = async () => Promise.resolve();
1280
+ const axios = async () => {
1281
+ return Promise.reject(new Error('Custom error'));
1282
+ };
1283
+
1284
+ let actual = null;
1285
+ try {
1286
+ await Support.sendRequest({ node, msg, config, axios, login, options });
1287
+ } catch (error) {
1288
+ actual = error;
1289
+ }
1290
+
1291
+ should.deepEqual(actual, new Error('Custom error'));
1292
+ });
1293
+
1294
+ it('should handle axios response error #1', async () => {
1295
+ const node = {
1296
+ send: () => {},
1297
+ context: () => {
1298
+ return {
1299
+ global: {
1300
+ get: (param) => {
1301
+ if (param == '_YOU_SapServiceLayer_1.host') {
1302
+ return 'host';
1303
+ }
1304
+ if (param == '_YOU_SapServiceLayer_1.port') {
1305
+ return 'port';
1306
+ }
1307
+ if (param == '_YOU_SapServiceLayer_1.version') {
1308
+ return 'version';
1309
+ }
1310
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1311
+ return ['header:1', 'header:2'];
1312
+ }
1313
+ },
1314
+ },
1315
+ };
1316
+ },
1317
+ };
1318
+
1319
+ const msg = {
1320
+ _YOU_SapServiceLayer: {
1321
+ idAuth: 1,
1322
+ },
1323
+ };
1324
+ const config = {
1325
+ entity: 'businessPartner',
1326
+ };
1327
+ const options = { method: 'GET', hasRawQuery: true };
1328
+
1329
+ const axiosError = {
1330
+ response: {
1331
+ data: 'Custom Error',
1332
+ },
1333
+ };
1334
+
1335
+ const expect = new Error(JSON.stringify(axiosError.response.data));
1336
+
1337
+ const login = async () => Promise.resolve({});
1338
+ const axios = async () => {
1339
+ return Promise.reject(axiosError);
1340
+ };
1341
+
1342
+ let actual = null;
1343
+ try {
1344
+ await Support.sendRequest({ node, msg, config, axios, login, options });
1345
+ } catch (error) {
1346
+ actual = error;
1347
+ }
1348
+
1349
+ should.deepEqual(actual, expect);
1350
+ });
1351
+
1352
+ it('should handle axios response error 401 #2', async () => {
1353
+ const node = {
1354
+ send: () => {},
1355
+ context: () => {
1356
+ return {
1357
+ global: {
1358
+ get: (param) => {
1359
+ if (param == '_YOU_SapServiceLayer_1.host') {
1360
+ return 'host';
1361
+ }
1362
+ if (param == '_YOU_SapServiceLayer_1.port') {
1363
+ return 'port';
1364
+ }
1365
+ if (param == '_YOU_SapServiceLayer_1.version') {
1366
+ return 'version';
1367
+ }
1368
+ if (param == '_YOU_SapServiceLayer_1.headers') {
1369
+ return ['header:1', 'header:2'];
1370
+ }
1371
+ },
1372
+ set: () => {},
1373
+ },
1374
+ };
1375
+ },
1376
+ };
1377
+
1378
+ const msg = {
1379
+ _YOU_SapServiceLayer: {
1380
+ idAuth: 1,
1381
+ },
1382
+ };
1383
+ const config = {
1384
+ entity: 'businessPartner',
1385
+ };
1386
+ const options = { method: 'GET', hasRawQuery: true };
1387
+
1388
+ const axiosError = {
1389
+ response: {
1390
+ status: 401,
1391
+ data: 'Custom Error',
1392
+ },
1393
+ };
1394
+
1395
+ const expect = new Error(JSON.stringify(axiosError.response.data));
1396
+
1397
+ const login = async () =>
1398
+ Promise.resolve({
1399
+ headers: {
1400
+ 'Content-Type': 'application/json',
1401
+ 'Content-Length': 100,
1402
+ 'set-cookie': 'cookie1=1;cookie2',
1403
+ },
1404
+ });
1405
+ const axios = async () => {
1406
+ return Promise.reject(axiosError);
1407
+ };
1408
+
1409
+ let actual = null;
1410
+ try {
1411
+ await Support.sendRequest({ node, msg, config, axios, login, options });
1412
+ } catch (error) {
1413
+ actual = error;
1414
+ }
1415
+
1416
+ should.deepEqual(actual, expect);
1417
+ });
1418
+ });
1419
+ });