biz-a-cli 2.3.73 → 2.3.74

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.
@@ -1,42 +0,0 @@
1
- const {
2
- getInputScript
3
- } = await import('../callbackController.js');
4
-
5
- describe('callback test', () => {
6
- test('get input script', () => {
7
- const args = {
8
- hostname: 'localhost',
9
- port: 212,
10
- dbindex: 2,
11
- subdomain: 'abc'
12
- };
13
-
14
- const request = {
15
- app: { settings: { args: args } },
16
- body: {
17
- body: { body1: 'value1' },
18
- headers: { connection: 'keep-alive' }
19
- },
20
- path: 'pqr',
21
- }
22
-
23
- expect(getInputScript(request)).toStrictEqual({
24
- data: {
25
- arguments: args,
26
- body: { body1: 'value1' },
27
- path: 'pqr',
28
- query: undefined,
29
- headers: {
30
- connection: 'keep-alive'
31
- },
32
- socket: undefined,
33
-
34
- },
35
- selectedConfig: {
36
- url: 'http://localhost:212',
37
- dbindex: 2,
38
- subdomain: 'abc'
39
- }
40
- });
41
- });
42
- })
@@ -1,39 +0,0 @@
1
- const {
2
- addUrlValue
3
- } = await import('../scheduler/configController.js');
4
-
5
- describe('config test', () => {
6
- test('url must be defined in config if undefined', () => {
7
- const CONFIG = [{
8
- _id: 'ffffffff2ae49fab9ea654e1',
9
- API_URL: 'http://localhost:212',
10
- dbindex: 2,
11
- subdomain: 'abc'
12
- }]
13
- expect(addUrlValue(CONFIG)).toStrictEqual([{
14
- _id: 'ffffffff2ae49fab9ea654e1',
15
- API_URL: 'http://localhost:212',
16
- dbindex: 2,
17
- subdomain: 'abc',
18
- url: 'http://localhost:212',
19
- }]);
20
- });
21
-
22
- test('url remain unchanged when exist', () => {
23
- const CONFIG = [{
24
- _id: 'ffffffff2ae49fab9ea654e1',
25
- API_URL: 'http://localhost:212',
26
- dbindex: 2,
27
- subdomain: 'abc',
28
- url: 'http://localhost:213'
29
- }]
30
- expect(addUrlValue(CONFIG)).toStrictEqual([{
31
- _id: 'ffffffff2ae49fab9ea654e1',
32
- API_URL: 'http://localhost:212',
33
- dbindex: 2,
34
- subdomain: 'abc',
35
- url: 'http://localhost:213',
36
- }]);
37
- });
38
- })
39
-
@@ -1,106 +0,0 @@
1
- const {
2
- historyRecordToJson,
3
- watcherRecordToJson,
4
- setUtcDate
5
- } = await import('../scheduler/converter.js');
6
-
7
- describe('converter test', () => {
8
- test('convert history record to json', async () => {
9
- const data = [{
10
- history_id: 1,
11
- timer_id: 2,
12
- latest_run: '01.03.2024, 14:43:27.899'
13
- }]
14
- expect(historyRecordToJson(data)).toStrictEqual([{
15
- _id: 1,
16
- timerObjectId: 2,
17
- latestRun: '01.03.2024, 14:43:27.899'
18
- }]);
19
- });
20
-
21
- test('convert watcher record to json', async () => {
22
- const data = [{
23
- watcher_id: 1,
24
- company_id: '62948492f7d559fba6f32196',
25
- timer_id: 1,
26
- timer_watcher_id: 1,
27
- name: 'New Watcher 1',
28
- active: true,
29
- timezone: 'Asia/Jakarta',
30
- templateName: 'cekUser.js',
31
- seq: 0,
32
- daily_days: '0,1,2,3,4,5,6',
33
- weekly_ordinal: '',
34
- weekly_days: '',
35
- monthly_days: '',
36
- minutely_everymin: 1,
37
- minutely_time_from: '08:00',
38
- minutely_time_to: '22:00',
39
- hourly_hours: '',
40
- scriptid: 1,
41
- cli_script: 'abc'
42
- }, {
43
- watcher_id: 1,
44
- company_id: '62948492f7d559fba6f32196',
45
- timer_id: 2,
46
- timer_watcher_id: 1,
47
- name: 'New Watcher 2',
48
- active: true,
49
- timezone: 'Asia/Makassar',
50
- templateName: 'cekUser2.js',
51
- seq: 1,
52
- daily_days: '',
53
- weekly_ordinal: '',
54
- weekly_days: '',
55
- monthly_days: '2,3',
56
- minutely_everymin: 0,
57
- minutely_time_from: '',
58
- minutely_time_to: '',
59
- hourly_hours: '12:00,13:00',
60
- scriptid: 2,
61
- cli_script: 'def'
62
- }]
63
-
64
- expect(watcherRecordToJson(data)).toStrictEqual([{
65
- _id: 1,
66
- companyObjectId: '62948492f7d559fba6f32196',
67
- timer: [{
68
- _id: 1,
69
- watcherObjectId: 1,
70
- name: 'New Watcher 1',
71
- active: true,
72
- timezone: 'Asia/Jakarta',
73
- templateName: 'cekUser.js',
74
- seq: 0,
75
- daily: [0, 1, 2, 3, 4, 5, 6],
76
- minutely: {
77
- everyMin: 1,
78
- from: '08:00',
79
- to: '22:00'
80
- },
81
- scriptid: 1,
82
- script: '"abc"'
83
- }, {
84
- _id: 2,
85
- watcherObjectId: 1,
86
- name: 'New Watcher 2',
87
- active: true,
88
- timezone: 'Asia/Makassar',
89
- templateName: 'cekUser2.js',
90
- seq: 1,
91
- monthly: [2, 3],
92
- hourly: ['12:00', '13:00'],
93
- scriptid: 2,
94
- script: '"def"'
95
-
96
- }]
97
- }]);
98
- });
99
-
100
- test('convert latestRun date to UTC Date', async () => {
101
- expect(setUtcDate('2024-05-21 7:57:57 AM'))
102
- .toStrictEqual(new Date('2024-05-21T07:57:57.000Z'));
103
- });
104
-
105
-
106
- })
@@ -1,487 +0,0 @@
1
- import { jest } from '@jest/globals'
2
-
3
- const mockInsertHistory = jest.fn();
4
- jest.unstable_mockModule("../scheduler/watcherController.js", () => ({
5
- insertHistory: mockInsertHistory.mockResolvedValue('OK'),
6
- }))
7
-
8
- let axios = (await import('axios')).default
9
-
10
- const {
11
- AXIOS_TIMEOUT,
12
- scheduleSubscription,
13
- getConfig,
14
- getInputData,
15
- getQueryDataPrmsParameters,
16
- mapData2Key,
17
- getUrlApi,
18
- json2Parameters,
19
- getUrlAndParam,
20
- getTableObj,
21
- options,
22
- setLibrary,
23
- extractFunctionScript
24
- } = await import('../scheduler/datalib.js');
25
-
26
- describe('data test', () => {
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
-
45
-
46
- test('check schedule subscription no history', async () => {
47
- const logSpy = jest.spyOn(console, 'log').mockImplementation();
48
-
49
- const config = {
50
- _id: 'ffffffff2ae49fab9ea654e1',
51
- url: 'http://localhost:212',
52
- dbindex: 2,
53
- subdomain: 'abc'
54
- }
55
- // const data = [{ script: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
56
- const data = [{ script: SCRIPT }];
57
-
58
- const trigger = {
59
- _id: 1,
60
- name: 'New Watcher 1',
61
- }
62
-
63
- await scheduleSubscription(config, data, trigger, false, true);
64
- expect(mockInsertHistory).toBeCalledTimes(0);
65
- expect(logSpy).toHaveBeenCalledWith('Run Schedule : New Watcher 1');
66
-
67
- logSpy.mockRestore();
68
- });
69
-
70
- test('check schedule subscription with history', async () => {
71
- const logSpy = jest.spyOn(console, 'log').mockImplementation();
72
- const config = {
73
- _id: 'ffffffff2ae49fab9ea654e1',
74
- url: 'http://localhost:212',
75
- dbindex: 2,
76
- subdomain: 'abc'
77
- }
78
-
79
- // const data = [{ script: '7b2266756e6374696f6e73223a7b226f6e496e6974223a5b2277696e646f772e46756e6374696f6e222c5b22636f6e666967222c222064617461225d2c5b2220202020202020202020202020202020636f6e737420646f6974203d206173796e63202829203d3e207b222c222020202020202020202020202020202020202020636f6e7374207b20746170207d203d20617761697420696d706f7274282772786a732729222c222020202020202020202020202020202020202020636f6e7374207b20717565727944617461207d203d20617761697420696d706f727428272e2f646174616c69622e6a732729222c222020202020202020202020202020202020202020636f6e737420706172616d203d207b222c222020202020202020202020202020202020202020202020206c656e6774683a2031302c222c22202020202020202020202020202020202020202020202020636f6c756d6e733a205b222c22202020202020202020202020202020202020202020202020202020207b20646174613a202755534552532e555345524944272c206b65793a202775736572696427207d222c222020202020202020202020202020202020202020202020205d2c222c222020202020202020202020202020202020202020202020206462496e6465783a2031222c2220202020202020202020202020202020202020207d222c22202020202020202020202020202020202020202071756572794461746128706172616d2c20636f6e6669672c2074727565292e7069706528222c2220202020202020202020202020202020202020202020202074617028726573203d3e20636f6e736f6c652e6c6f672872657329292c222c222020202020202020202020202020202020202020292e73756273637269626528726573203d3e207b222c22202020202020202020202020202020202020202020202020636f6e736f6c652e6c6f67287265732c20277375627363726962652729222c2220202020202020202020202020202020202020207d29222c22202020202020202020202020202020207d222c2220202020202020202020202020202020646f69742829222c222020202020202020202020202020202072657475726e20276f6b20646172692063656b55736572273b225d5d7d7d' }]
80
- const data = [{ script: SCRIPT }];
81
-
82
- const trigger = {
83
- _id: 1,
84
- name: 'New Watcher 1'
85
- }
86
-
87
- await scheduleSubscription(config, data, trigger, true, true);
88
- expect(mockInsertHistory).toBeCalledTimes(1);
89
- expect(logSpy).toHaveBeenCalledWith('Run Recent Schedule : New Watcher 1');
90
-
91
- logSpy.mockRestore();
92
- });
93
-
94
- test('get input data', () => {
95
- const config = {
96
- _id: 'ffffffff2ae49fab9ea654e1',
97
- url: 'http://localhost:212',
98
- dbindex: 2,
99
- finaDbIndex: 1,
100
- subdomain: 'abc',
101
- smtp: {
102
- auth: {
103
- user: 'abc',
104
- pass: '123'
105
- },
106
- host: 'mail.imamatek.com',
107
- port: 465,
108
- secure: true
109
- }
110
- }
111
- const trigger = {
112
- data: {
113
- _id: 1,
114
- name: 'New Watcher 1'
115
- }
116
- }
117
-
118
- expect(getInputData(config, trigger)).toStrictEqual({
119
- arguments: {
120
- hostname: 'localhost',
121
- port: 212,
122
- dbindex: config.dbindex,
123
- finaDbIndex: config.finaDbIndex,
124
- subdomain: config.subdomain,
125
- smtp: config.smtp
126
- },
127
- body: trigger.data
128
- });
129
- });
130
-
131
- test('get config', () => {
132
- const config = {
133
- _id: 'ffffffff2ae49fab9ea654e1',
134
- url: 'localhost'
135
- }
136
-
137
- expect(getConfig(config)).toStrictEqual(config);
138
- });
139
-
140
- test('get config array', () => {
141
- const config = [{
142
- _id: 'ffffffff2ae49fab9ea654e1',
143
- url: 'localhost'
144
- }]
145
-
146
- expect(getConfig(config)).toStrictEqual(config[0]);
147
- });
148
-
149
- test('get query data parameter', () => {
150
- expect(getQueryDataPrmsParameters('ID', 12)).toStrictEqual({
151
- length: 1,
152
- filter: [{ junction: '', column: 'ID', operator: '=', value1: "'12'" }],
153
- columns: [{ data: "SYS$CLI_SCRIPT.SCRIPT", key: 'script' }]
154
- });
155
- });
156
-
157
- test('should map data correctly when key is provided', () => {
158
- const res = [
159
- { id: 1, name: 'Alice' },
160
- { id: 2, name: 'Bob' },
161
- ];
162
- const cols = [
163
- { key: 'identifier', data: 'id' },
164
- { key: 'fullName', data: 'name' },
165
- ];
166
-
167
- const result = mapData2Key(res, cols);
168
- expect(result).toEqual([
169
- { identifier: 1, fullName: 'Alice' },
170
- { identifier: 2, fullName: 'Bob' },
171
- ]);
172
- });
173
-
174
- test('should map data correctly when key is not provided', () => {
175
- const res = [
176
- { id: 1, name: 'Alice' },
177
- { id: 2, name: 'Bob' },
178
- ];
179
- const cols = [
180
- { data: 'id' },
181
- { data: 'name' },
182
- ];
183
-
184
- const result = mapData2Key(res, cols);
185
- expect(result).toEqual([
186
- { id: 1, name: 'Alice' },
187
- { id: 2, name: 'Bob' },
188
- ]);
189
- });
190
-
191
- test('should handle an empty result set', () => {
192
- const res = [];
193
- const cols = [
194
- { key: 'identifier', data: 'id' },
195
- { key: 'fullName', data: 'name' },
196
- ];
197
-
198
- const result = mapData2Key(res, cols);
199
- expect(result).toEqual([]);
200
- });
201
-
202
- test('should handle an empty column set', () => {
203
- const res = [
204
- { id: 1, name: 'Alice' },
205
- { id: 2, name: 'Bob' },
206
- ];
207
- const cols = [];
208
-
209
- const result = mapData2Key(res, cols);
210
- expect(result).toEqual([{}, {}]);
211
- });
212
-
213
- test('should handle null and undefined values in the data', () => {
214
- const res = [
215
- { id: 1, name: null },
216
- { id: null, name: 'Bob' },
217
- ];
218
- const cols = [
219
- { key: 'identifier', data: 'id' },
220
- { key: 'fullName', data: 'name' },
221
- ];
222
-
223
- const result = mapData2Key(res, cols);
224
- expect(result).toEqual([
225
- { identifier: 1, fullName: null },
226
- { identifier: null, fullName: 'Bob' },
227
- ]);
228
- });
229
-
230
- test('should return the correct URL for POST requests', () => {
231
- const config = { url: 'http://example.com' };
232
- const methodName = 'testMethod';
233
- const isPost = true;
234
- const expectedUrl = 'http://example.com/fina/rest/TOrmMethod/%22testMethod%22';
235
-
236
- expect(getUrlApi(config, methodName, isPost)).toBe(expectedUrl);
237
- });
238
-
239
- test('should return the correct URL for GET requests with custom class', () => {
240
- const config = { url: 'http://example.com', methodClass: 'TFinaMethod' };
241
- const methodName = 'testMethod';
242
- const isPost = false;
243
- const expectedUrl = 'http://example.com/fina/rest/TFinaMethod/testMethod';
244
-
245
- expect(getUrlApi(config, methodName, isPost)).toBe(expectedUrl);
246
- });
247
-
248
- test('should convert an array of objects to a JSON string with a _parameters key', () => {
249
- const input = [{ a: 1 }, { b: 2 }];
250
- const expectedOutput = JSON.stringify({ _parameters: [JSON.stringify({ a: 1 }), JSON.stringify({ b: 2 })] });
251
-
252
- expect(json2Parameters(input)).toBe(expectedOutput);
253
- });
254
-
255
- test('should handle an empty array', () => {
256
- const input = [];
257
- const expectedOutput = JSON.stringify({ _parameters: [] });
258
-
259
- expect(json2Parameters(input)).toBe(expectedOutput);
260
- });
261
-
262
- test('should return correct url and params', () => {
263
- const config = {
264
- url: 'https://example.com',
265
- dbindex: '1'
266
- };
267
- const method = 'POST';
268
- const obj = { id: 1 };
269
- const path = 'testMethod';
270
- const result = getUrlAndParam(config, method, obj, path);
271
-
272
- expect(result).toEqual({
273
- url: 'https://example.com/fina/rest/TOrmMethod/%22testMethod%22',
274
- params: "{\"_parameters\":[\"{\\\"dbIndex\\\":\\\"1\\\",\\\"method\\\":\\\"POST\\\",\\\"object\\\":{\\\"id\\\":1}}\"]}"
275
- });
276
- });
277
-
278
- test('should get table object', () => {
279
- const model = { id: 1, name: 'testModel' };
280
- const tableName = 'testTable';
281
-
282
- const result = getTableObj(model, tableName);
283
-
284
- let expected = {};
285
- expected[tableName] = model;
286
- expect(result).toEqual(expected);
287
- });
288
-
289
- test('should return the correct headers and params', () => {
290
- const apiConfig = { subdomain: 'example' };
291
- const expectedResult = {
292
- headers: { 'content-type': 'text/plain' },
293
- params: { subdomain: 'example' },
294
- timeout: AXIOS_TIMEOUT
295
- };
296
-
297
- const result = options(apiConfig);
298
- expect(result).toStrictEqual(expectedResult);
299
- });
300
-
301
- test('should handle missing subdomain in apiConfig', () => {
302
- const apiConfig = { timeout: 123 };
303
- const expectedResult = {
304
- headers: { 'content-type': 'text/plain' },
305
- params: { subdomain: undefined },
306
- timeout: 123
307
- };
308
-
309
- const result = options(apiConfig);
310
- expect(result).toStrictEqual(expectedResult);
311
- });
312
-
313
- test('should set library if any', async () => {
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
- }
326
- }
327
- return doit()
328
- },
329
- zzz: function () {
330
- return lib;
331
- }
332
- }
333
- }
334
- }`
335
- }]
336
- })
337
-
338
- const config = {};
339
- const libraries = ['libCb'];
340
- const defaultLib = { defA: 'A', defB: 'B' }
341
-
342
- const result = await setLibrary(config, libraries, defaultLib);
343
-
344
- expect(result.libCb.yyy().abc()).toStrictEqual('abc');
345
- expect(result.libCb.zzz()).toStrictEqual({ "defA": "A", "defB": "B" });
346
- });
347
-
348
- test('should return undefined when data has error', async () => {
349
- const logSpy = jest.spyOn(console, 'log').mockImplementation();
350
-
351
- const config = {};
352
- const data = { error: 'error' };
353
-
354
- const actual = await extractFunctionScript(config, data);
355
- const expected = undefined;
356
-
357
- expect(actual).toStrictEqual(expected);
358
- expect(logSpy).toHaveBeenCalledWith('error', 'error');
359
-
360
- logSpy.mockRestore();
361
- });
362
-
363
- test('should return undefined when no data', async () => {
364
- const config = {};
365
- const data = [];
366
-
367
- const actual = await extractFunctionScript(config, data);
368
- const expected = undefined;
369
-
370
- expect(actual).toStrictEqual(expected);
371
- });
372
-
373
- test('should return undefined when no functions', async () => {
374
- const config = {};
375
- const data = [{
376
- script: `get = function () {
377
- return {}
378
- }`
379
- }];
380
-
381
- const actual = await extractFunctionScript(config, data);
382
- const expected = undefined;
383
-
384
- expect(actual).toStrictEqual(expected);
385
- });
386
-
387
- test('should return onInit', async () => {
388
- const config = {};
389
- const data = [{
390
- script: `get = function () {
391
- return {
392
- functions: {
393
- onInit: function (data) {
394
- return 'OK'
395
- }
396
- }
397
- }
398
- }`
399
- }];
400
-
401
-
402
- const actual = await extractFunctionScript(config, data);
403
- const expected = 'OK';
404
-
405
- expect(actual.onInit()).toStrictEqual(expected);
406
- });
407
-
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
- });
486
- })
487
-