biz-a-cli 2.3.63 → 2.3.65

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.
@@ -5,13 +5,10 @@ jest.unstable_mockModule("../scheduler/watcherController.js", () => ({
5
5
  insertHistory: mockInsertHistory.mockResolvedValue('OK'),
6
6
  }))
7
7
 
8
- jest.unstable_mockModule('axios', () => { return { default: jest.fn() } })
9
8
  let axios = (await import('axios')).default
10
9
 
11
- axios.get = jest.fn()
12
- axios.post = jest.fn()
13
-
14
10
  const {
11
+ AXIOS_TIMEOUT,
15
12
  scheduleSubscription,
16
13
  getConfig,
17
14
  getInputData,
@@ -27,23 +24,24 @@ const {
27
24
  } = await import('../scheduler/datalib.js');
28
25
 
29
26
  describe('data test', () => {
30
- const SCRIPT = "get = function () {" +
31
- " return {" +
32
- " functions: {" +
33
- " onInit: function (data) {" +
34
- " const doit = async () => {" +
35
- " const config = {" +
36
- " url: `http://${data.arguments.hostname}:${data.arguments.port}`," +
37
- " dbindex: data.arguments.dbindex," +
38
- " subdomain: data.arguments.subdomain" +
39
- " };" +
40
- " };" +
41
- " doit();" +
42
- " return 'OK';" +
43
- " }" +
44
- " }" +
45
- " }" +
46
- "}";
27
+ const SCRIPT = `get = function () {
28
+ return {
29
+ functions: {
30
+ onInit: function (data) {
31
+ const doit = async () => {
32
+ const config = {
33
+ url: \`http://\${data.arguments.hostname}:\${data.arguments.port}\`,
34
+ dbindex: data.arguments.dbindex,
35
+ subdomain: data.arguments.subdomain
36
+ };
37
+ };
38
+ doit();
39
+ return 'OK';
40
+ }
41
+ }
42
+ }
43
+ }`;
44
+
47
45
 
48
46
  test('check schedule subscription no history', async () => {
49
47
  const logSpy = jest.spyOn(console, 'log').mockImplementation();
@@ -292,50 +290,50 @@ describe('data test', () => {
292
290
  const apiConfig = { subdomain: 'example' };
293
291
  const expectedResult = {
294
292
  headers: { 'content-type': 'text/plain' },
295
- params: { subdomain: 'example' }
293
+ params: { subdomain: 'example' },
294
+ timeout: AXIOS_TIMEOUT
296
295
  };
297
296
 
298
297
  const result = options(apiConfig);
299
- expect(result).toEqual(expectedResult);
298
+ expect(result).toStrictEqual(expectedResult);
300
299
  });
301
300
 
302
301
  test('should handle missing subdomain in apiConfig', () => {
303
- const apiConfig = {};
302
+ const apiConfig = { timeout: 123 };
304
303
  const expectedResult = {
305
304
  headers: { 'content-type': 'text/plain' },
306
- params: { subdomain: undefined }
305
+ params: { subdomain: undefined },
306
+ timeout: 123
307
307
  };
308
308
 
309
309
  const result = options(apiConfig);
310
- expect(result).toEqual(expectedResult);
310
+ expect(result).toStrictEqual(expectedResult);
311
311
  });
312
312
 
313
313
  test('should set library if any', async () => {
314
- axios.post.mockResolvedValueOnce(axios.post.mockResolvedValueOnce({
315
- data: [
316
- {
317
- 'SYS$CLI_SCRIPT.SCRIPT': 'get = function (lib) {\n' +
318
- ' return {\n' +
319
- ' functions: {\n' +
320
- ' yyy: function (data) {\n' +
321
- ' function doit() {\n' +
322
- ' return {\n' +
323
- ' abc: function () {\n' +
324
- " return 'abc';\n" +
325
- ' },\n' +
326
- ' }\n' +
327
- ' }\n' +
328
- ' return doit()\n' +
329
- ' },\n' +
330
- ' zzz: function () {\n' +
331
- " return lib;\n" +
332
- ' }\n' +
333
- ' }\n' +
334
- ' }\n' +
335
- '}'
314
+ axios.post = jest.fn().mockResolvedValueOnce({
315
+ data: [{
316
+ 'SYS$CLI_SCRIPT.SCRIPT': `get = function (lib) {
317
+ return {
318
+ functions: {
319
+ yyy: function (data) {
320
+ function doit() {
321
+ return {
322
+ abc: function () {
323
+ return 'abc';
324
+ },
325
+ }
336
326
  }
337
- ]
338
- }))
327
+ return doit()
328
+ },
329
+ zzz: function () {
330
+ return lib;
331
+ }
332
+ }
333
+ }
334
+ }`
335
+ }]
336
+ })
339
337
 
340
338
  const config = {};
341
339
  const libraries = ['libCb'];
@@ -375,9 +373,9 @@ describe('data test', () => {
375
373
  test('should return undefined when no functions', async () => {
376
374
  const config = {};
377
375
  const data = [{
378
- script: 'get = function () {\n' +
379
- ' return {}\n' +
380
- '}'
376
+ script: `get = function () {
377
+ return {}
378
+ }`
381
379
  }];
382
380
 
383
381
  const actual = await extractFunctionScript(config, data);
@@ -389,44 +387,101 @@ describe('data test', () => {
389
387
  test('should return onInit', async () => {
390
388
  const config = {};
391
389
  const data = [{
392
- script: 'get = function () {\n' +
393
- ' return {\n' +
394
- ' functions: {\n' +
395
- ' onInit: function (data) {\n' +
396
- " return 'OK'\n" +
397
- ' }\n' +
398
- ' }\n' +
399
- ' }\n' +
400
- '}'
390
+ script: `get = function () {
391
+ return {
392
+ functions: {
393
+ onInit: function (data) {
394
+ return 'OK'
395
+ }
396
+ }
397
+ }
398
+ }`
401
399
  }];
402
400
 
401
+
403
402
  const actual = await extractFunctionScript(config, data);
404
403
  const expected = 'OK';
405
404
 
406
405
  expect(actual.onInit()).toStrictEqual(expected);
407
406
  });
408
407
 
409
- // test('should return useLibrary', async () => { // not work, cannot mock useLibrary. Try later
410
- // const config = {};
411
- // const data = [{
412
- // script: 'get = function () {\n' +
413
- // ' return {\n' +
414
- // ' functions: {\n' +
415
- // ' onInit: function (data) {\n' +
416
- // " return 'OK'\n" +
417
- // ' },\n' +
418
- // ' useLibrary: function () {\n' +
419
- // ' return ["lib"];\n' +
420
- // ' }\n' +
421
- // ' }\n' +
422
- // ' }\n' +
423
- // '}'
424
- // }];
425
-
426
- // const actual = await extractFunctionScript(config, data);
427
- // const expected = 'OK';
428
-
429
- // expect(actual.onInit()).toStrictEqual(expected);
430
- // });
408
+ test('should show axios default timeout', async () => {
409
+ const config = {};
410
+ const data = [{
411
+ script: `get = function (lib) {
412
+ return {
413
+ functions: {
414
+ onInit: function (data) {
415
+ return lib.axios.defaults.timeout;
416
+ }
417
+ }
418
+ }
419
+ }`
420
+ }];
421
+
422
+ const actual = await extractFunctionScript(config, data);
423
+ const expected = AXIOS_TIMEOUT;
424
+
425
+ expect(actual.onInit()).toStrictEqual(expected);
426
+ });
427
+
428
+ test('should show axios custom timeout', async () => {
429
+ const CUSTOM_TIMEOUT = 25000;
430
+ const config = {};
431
+ const data = [{
432
+ script: `get = function (lib) {
433
+ return {
434
+ functions: {
435
+ onInit: function (data) {
436
+ lib.axios.defaults.timeout = ${CUSTOM_TIMEOUT};
437
+ return lib.axios.defaults.timeout;
438
+ }
439
+ }
440
+ }
441
+ }`
442
+ }];
443
+
444
+ const actual = await extractFunctionScript(config, data);
445
+ const expected = CUSTOM_TIMEOUT;
446
+
447
+ expect(actual.onInit()).toStrictEqual(expected);
448
+ });
449
+
450
+ test('should return useLibrary', async () => {
451
+ axios.post = jest.fn().mockResolvedValueOnce({
452
+ data: [{
453
+ "SYS$CLI_SCRIPT.SCRIPT": `get = function (lib) {
454
+ return {
455
+ functions: {
456
+ abc: function () {
457
+ return 'abcFn';
458
+ }
459
+ }
460
+ }
461
+ }`
462
+ }]
463
+ });
464
+
465
+ const config = {};
466
+ const data = [{
467
+ script: `get = function (lib) {
468
+ return {
469
+ functions: {
470
+ useLibrary: function () {
471
+ return ["abcLib"];
472
+ },
473
+ onInit: function (data) {
474
+ return lib.abcLib.abc();
475
+ }
476
+ }
477
+ }
478
+ }`
479
+ }];
480
+
481
+ const actual = await extractFunctionScript(config, data);
482
+ const expected = 'abcFn';
483
+
484
+ expect(actual.onInit()).toStrictEqual(expected);
485
+ });
431
486
  })
432
487