biz-a-cli 2.3.33 → 2.3.35
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.
- package/bin/hub.js +23 -0
- package/bin/log/debug.log +345 -0
- package/bin/log/error.log +55 -0
- package/bin/log/exception.log +309 -0
- package/bin/log/info.log +123 -0
- package/bin/pmtGateway.js +68 -0
- package/bin/watcher.js +15 -1
- package/callbackController.js +34 -2
- package/envs/env.dev.js +9 -3
- package/envs/env.js +6 -1
- package/package.json +4 -2
- package/pmtGatewayController.js +55 -0
- package/scheduler/datalib.js +36 -12
- package/tests/app.test.js +4 -4
- package/tests/callback.test.js +17 -2
- package/tests/data.test.js +47 -9
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import yargs from 'yargs';
|
|
4
|
+
import { createLogger, transports, format } from "winston";
|
|
5
|
+
import {
|
|
6
|
+
sendInquiry,
|
|
7
|
+
sendPaymentNotif,
|
|
8
|
+
} from "../pmtGatewayController.js";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const logger = createLogger({
|
|
12
|
+
level: 'info',
|
|
13
|
+
transports: [
|
|
14
|
+
new transports.File({ filename: 'log/error.log', level: 'error' }),
|
|
15
|
+
new transports.File({ filename: 'log/debug.log', level: 'debug' }),
|
|
16
|
+
new transports.File({ filename: 'log/info.log', level: 'info' }),
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
20
|
+
logger.add(new transports.Console({ format: format.simple(), level: 'info' }))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
process.on('uncaughtException', (err) => { //debug
|
|
24
|
+
console.log('Unhandled Exception:', err);
|
|
25
|
+
logger.error('Unhandled Exception:', err)
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
process.on('unhandledRejection', (err) => { //debug
|
|
29
|
+
console.log('Unhandled Rejection:', err);
|
|
30
|
+
logger.error('Unhandled Rejection:', err)
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const port = 3003;
|
|
34
|
+
const argv = yargs(process.argv.slice(2))
|
|
35
|
+
.usage('Usage: $0 [options]')
|
|
36
|
+
.options('sp', {
|
|
37
|
+
alias: 'serverport',
|
|
38
|
+
default: port,
|
|
39
|
+
describe: 'Express Port (Callback Feature)',
|
|
40
|
+
type: 'number',
|
|
41
|
+
demandOption: false
|
|
42
|
+
})
|
|
43
|
+
.argv;
|
|
44
|
+
|
|
45
|
+
if (argv.help) {
|
|
46
|
+
yargs().showHelp();
|
|
47
|
+
process.exit();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//
|
|
51
|
+
import express from 'express';
|
|
52
|
+
import cors from 'cors';
|
|
53
|
+
const app = express();
|
|
54
|
+
|
|
55
|
+
app.use(cors());
|
|
56
|
+
app.use(express.json());
|
|
57
|
+
|
|
58
|
+
app.set('args', argv);
|
|
59
|
+
|
|
60
|
+
app.use('/v1.0/transfer-va/inquiry', sendInquiry);
|
|
61
|
+
app.use('/v1.0/transfer-va/payment', sendPaymentNotif);
|
|
62
|
+
|
|
63
|
+
app.listen((argv.serverport || port), () => {
|
|
64
|
+
console.log(`Biz-A is listening at ${process.env.HOST || 'http://localhost'}:${argv.serverport || port} `);
|
|
65
|
+
});
|
|
66
|
+
//
|
|
67
|
+
|
|
68
|
+
export { app }
|
package/bin/watcher.js
CHANGED
|
@@ -4,15 +4,29 @@ import express from 'express';
|
|
|
4
4
|
import cors from 'cors';
|
|
5
5
|
const app = express();
|
|
6
6
|
import yargs from 'yargs';
|
|
7
|
-
|
|
8
7
|
import * as timer from '../scheduler/timer.js'
|
|
8
|
+
import { createLogger, transports, format } from "winston";
|
|
9
|
+
|
|
10
|
+
const logger = createLogger({
|
|
11
|
+
level: 'info',
|
|
12
|
+
transports: [
|
|
13
|
+
new transports.File({ filename: 'log/error.log', level: 'error' }),
|
|
14
|
+
new transports.File({ filename: 'log/debug.log', level: 'debug' }),
|
|
15
|
+
new transports.File({ filename: 'log/info.log', level: 'info' }),
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
19
|
+
logger.add(new transports.Console({ format: format.simple(), level: 'info' }))
|
|
20
|
+
}
|
|
9
21
|
|
|
10
22
|
process.on('uncaughtException', (err) => { //debug
|
|
11
23
|
console.log('Unhandled Exception:', err);
|
|
24
|
+
logger.error('Unhandled Exception:', err)
|
|
12
25
|
});
|
|
13
26
|
|
|
14
27
|
process.on('unhandledRejection', (err) => { //debug
|
|
15
28
|
console.log('Unhandled Rejection:', err);
|
|
29
|
+
logger.error('Unhandled Rejection:', err)
|
|
16
30
|
});
|
|
17
31
|
|
|
18
32
|
const port = 3001;
|
package/callbackController.js
CHANGED
|
@@ -20,14 +20,46 @@ export function getInputScript(req) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function rawHeadersToHeaders(rawHeaders) {
|
|
24
|
+
const headers = {};
|
|
25
|
+
|
|
26
|
+
for (let headerIdx = 0; headerIdx < rawHeaders.length; headerIdx += 2) {
|
|
27
|
+
const key = rawHeaders[headerIdx].toLowerCase();
|
|
28
|
+
const value = rawHeaders[headerIdx + 1];
|
|
29
|
+
|
|
30
|
+
if (headers[key]) {
|
|
31
|
+
headers[key] += `, ${value}`;
|
|
32
|
+
} else {
|
|
33
|
+
headers[key] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return headers;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setDirectHubData(req) {
|
|
41
|
+
return {
|
|
42
|
+
body: {
|
|
43
|
+
query: req.query,
|
|
44
|
+
body: req.body,
|
|
45
|
+
headers: rawHeadersToHeaders(req.rawHeaders)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
23
50
|
export async function runCliScript(req, res) {
|
|
24
51
|
try {
|
|
52
|
+
if (!req.body.query) {
|
|
53
|
+
Object.assign(req, setDirectHubData(req))
|
|
54
|
+
};
|
|
55
|
+
|
|
25
56
|
const { data, selectedConfig } = getInputScript(req);
|
|
26
|
-
let script = await loadCliScript(selectedConfig, req.body.query);
|
|
27
|
-
let functions = extractFunctionScript(script);
|
|
57
|
+
let script = await loadCliScript(selectedConfig, 'ID', req.body.query.scriptid);
|
|
58
|
+
let functions = await extractFunctionScript(selectedConfig, script);
|
|
28
59
|
if (functions) {
|
|
29
60
|
let respon = await functions.onInit(data);
|
|
30
61
|
res.send(respon);
|
|
62
|
+
|
|
31
63
|
console.log(`Run Callback Successfully!`);
|
|
32
64
|
} else {
|
|
33
65
|
res.send('CLI Script does not exist.');
|
package/envs/env.dev.js
CHANGED
|
@@ -5,7 +5,13 @@ export const envDev = {
|
|
|
5
5
|
CDM_MONGO_LINK: 'mongodb+srv://imm_cdm:' +
|
|
6
6
|
encodeURIComponent('imm@2019') + '@imm-cdm-dev.rf6wr.mongodb.net/?retryWrites=true&w=majority',
|
|
7
7
|
COMPANY_REGISTER: 'companyregister-dev',
|
|
8
|
-
BIZA_SERVER_LINK: 'https://biz-a-dev-41e7c93a25e5.herokuapp.com'
|
|
9
|
-
// BIZA_SERVER_LINK: '
|
|
10
|
-
|
|
8
|
+
BIZA_SERVER_LINK: 'https://biz-a-dev-41e7c93a25e5.herokuapp.com',
|
|
9
|
+
// BIZA_SERVER_LINK: 'http://localhost:3000',
|
|
10
|
+
ESPAY_INQUIRY_LINK: 'http://localhost:3002/cb?subdomain=anejandev&companyid=anejandev&scriptid=5',
|
|
11
|
+
ESPAY_PAYMENT_LINK: 'http://localhost:3002/cb?subdomain=SACHLI&companyid=immdev&scriptid=6',
|
|
12
|
+
// ESPAY_INQUIRY_LINK: 'https://biz-a.herokuapp.com/cb?subdomain=anejandev&companyid=anejandev&scriptid=5',
|
|
13
|
+
// ESPAY_PAYMENT_LINK: 'https://biz-a.herokuapp.com/cb?subdomain=SACHLI&companyid=immdev&scriptid=6',
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
11
17
|
};
|
package/envs/env.js
CHANGED
|
@@ -5,5 +5,10 @@ export const env = {
|
|
|
5
5
|
CDM_MONGO_LINK: 'mongodb+srv://imm_cdm:' +
|
|
6
6
|
encodeURIComponent('imm@2019') + '@imm-cdm.ohcqt.mongodb.net/?retryWrites=true&w=majority',
|
|
7
7
|
COMPANY_REGISTER: 'companyregister',
|
|
8
|
-
BIZA_SERVER_LINK: 'https://biz-a.herokuapp.com'
|
|
8
|
+
BIZA_SERVER_LINK: 'https://biz-a.herokuapp.com',
|
|
9
|
+
// ESPAY_INQUIRY_LINK: 'http://localhost:3002/cb?subdomain=scya&companyid=scy&scriptid=5',
|
|
10
|
+
ESPAY_INQUIRY_LINK: 'http://localhost:3002/cb?subdomain=anejan&companyid=anejan&scriptid=4',
|
|
11
|
+
ESPAY_PAYMENT_LINK: 'http://localhost:3002/cb?subdomain=imm&companyid=imamatek&scriptid=7',
|
|
12
|
+
// ESPAY_INQUIRY_LINK: 'https://biz-a.herokuapp.com/cb?subdomain=anejandev&companyid=anejandev&scriptid=5',
|
|
13
|
+
// ESPAY_PAYMENT_LINK: 'https://biz-a.herokuapp.com/cb?subdomain=SACHLI&companyid=immdev&scriptid=6',
|
|
9
14
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biz-a-cli",
|
|
3
3
|
"nameDev": "biz-a-cli-dev",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.35",
|
|
5
5
|
"versionDev": "0.0.30",
|
|
6
6
|
"description": "",
|
|
7
7
|
"main": "bin/index.js",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"test1": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
16
16
|
"dev": "node --watch server.js",
|
|
17
17
|
"hub": "node --experimental-vm-modules bin/hub.js"
|
|
18
|
+
|
|
18
19
|
},
|
|
19
20
|
"author": "Imamatek",
|
|
20
21
|
"license": "ISC",
|
|
@@ -25,7 +26,8 @@
|
|
|
25
26
|
"watcher": "bin/watcher.js",
|
|
26
27
|
"uploadapp": "bin/uploadApp.js",
|
|
27
28
|
"deleteapp": "bin/deleteApp.js",
|
|
28
|
-
"biza": "bin/app.js"
|
|
29
|
+
"biza": "bin/app.js",
|
|
30
|
+
"pmtGateway": "bin/pmtGateway.js"
|
|
29
31
|
},
|
|
30
32
|
"dependencies": {
|
|
31
33
|
"axios": "^1.6.8",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { default as axios } from 'axios';
|
|
2
|
+
import { envDev } from './envs/env.dev.js';
|
|
3
|
+
import { env } from './envs/env.js';
|
|
4
|
+
|
|
5
|
+
import dayjs from "dayjs";
|
|
6
|
+
import utc from "dayjs/plugin/utc.js";
|
|
7
|
+
import timezone from "dayjs/plugin/timezone.js"
|
|
8
|
+
|
|
9
|
+
dayjs.extend(timezone)
|
|
10
|
+
dayjs.extend(utc)
|
|
11
|
+
|
|
12
|
+
const TIME_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ'
|
|
13
|
+
let ESPAY_INQUIRY_LINK;
|
|
14
|
+
let ESPAY_PAYMENT_LINK;
|
|
15
|
+
|
|
16
|
+
if ((process.env.NODE_ENV == undefined) || (process.env.NODE_ENV == 'development')) {
|
|
17
|
+
ESPAY_INQUIRY_LINK = envDev.ESPAY_INQUIRY_LINK;
|
|
18
|
+
ESPAY_PAYMENT_LINK = envDev.ESPAY_PAYMENT_LINK;
|
|
19
|
+
|
|
20
|
+
console.log('ESPAY_INQUIRY_LINK =>', ESPAY_INQUIRY_LINK);
|
|
21
|
+
console.log('ESPAY_PAYMENT_LINK =>', ESPAY_PAYMENT_LINK);
|
|
22
|
+
} else {
|
|
23
|
+
ESPAY_INQUIRY_LINK = env.ESPAY_INQUIRY_LINK;
|
|
24
|
+
ESPAY_PAYMENT_LINK = env.ESPAY_PAYMENT_LINK;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function sendData(req, res, url) {
|
|
28
|
+
const headers = {
|
|
29
|
+
'content-type': req.headers['content-type'],
|
|
30
|
+
'x-timestamp': req.headers['x-timestamp'],
|
|
31
|
+
'x-signature': req.headers['x-signature'],
|
|
32
|
+
'channel-id': req.headers['channel-id'],
|
|
33
|
+
'x-external-id': req.headers['x-external-id'],
|
|
34
|
+
'x-partner-id': req.headers['x-partner-id'],
|
|
35
|
+
'imm-original-url': req.originalUrl
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
res.setHeader('x-timestamp', dayjs().tz('Asia/jakarta').format(TIME_FORMAT));
|
|
39
|
+
|
|
40
|
+
const result = await axios.post(url, req.body, { headers });
|
|
41
|
+
res.send(result.data);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function sendInquiry(req, res) {
|
|
45
|
+
await sendData(req, res, ESPAY_INQUIRY_LINK);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function sendPaymentNotif(req, res) {
|
|
49
|
+
await sendData(req, res, ESPAY_PAYMENT_LINK);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
sendInquiry,
|
|
54
|
+
sendPaymentNotif
|
|
55
|
+
};
|
package/scheduler/datalib.js
CHANGED
|
@@ -147,46 +147,69 @@ export async function genId(apiConfig, genName) {
|
|
|
147
147
|
return res.data?.data ? JSON.parse(res.data.data) : res.data;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
function runScriptInThisContext(script) {
|
|
151
|
+
return runInThisContext(script, { importModuleDynamically: constants.USE_MAIN_CONTEXT_DEFAULT_LOADER });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function setLibrary(config, libraries) {
|
|
155
|
+
let libs = {};
|
|
156
|
+
for (const lib of libraries) {
|
|
157
|
+
const data = await loadCliScript(config, 'SCRIPT_NAME', lib);
|
|
158
|
+
const libFn = runScriptInThisContext(data[0].script);
|
|
159
|
+
Object.assign(libs, { lib: libFn().functions });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return libs;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function extractFunctionScript(selectedConfig, data) {
|
|
166
|
+
const config = getConfig(selectedConfig);
|
|
167
|
+
|
|
151
168
|
if (data.error) {
|
|
152
169
|
console.log(data.error, 'error')
|
|
153
170
|
return
|
|
154
171
|
}
|
|
155
172
|
if (data.length == 0) return
|
|
156
173
|
|
|
157
|
-
const scriptFn =
|
|
174
|
+
const scriptFn = runScriptInThisContext(data[0].script);
|
|
158
175
|
if (!scriptFn().functions) return
|
|
176
|
+
|
|
159
177
|
let lib = {
|
|
160
178
|
axios: axios.default,
|
|
161
179
|
dayjs: dayjs.default,
|
|
162
180
|
crypto: crypto,
|
|
163
|
-
log: logger
|
|
181
|
+
log: logger
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (scriptFn().functions.useLibrary) {
|
|
185
|
+
Object.assign(lib, await setLibrary(config, scriptFn().functions.useLibrary()));
|
|
164
186
|
}
|
|
165
187
|
return scriptFn(lib).functions;
|
|
166
188
|
}
|
|
167
189
|
|
|
168
|
-
export function
|
|
190
|
+
export function getQueryDataPrmsParameters(column, value) {
|
|
169
191
|
return {
|
|
170
192
|
length: 1,
|
|
171
|
-
filter: [{ junction: '', column:
|
|
193
|
+
filter: [{ junction: '', column: column, operator: '=', value1: `'${value}'` }],
|
|
172
194
|
columns: [{ data: "SYS$CLI_SCRIPT.SCRIPT", key: 'script' }]
|
|
173
195
|
}
|
|
174
196
|
}
|
|
175
197
|
|
|
176
|
-
export function queryDataPromise(config,
|
|
177
|
-
let param =
|
|
198
|
+
export async function queryDataPromise(config, column, value) {
|
|
199
|
+
let param = getQueryDataPrmsParameters(column, value);
|
|
200
|
+
// let param = getQueryDataPrmsParameters(d);
|
|
178
201
|
|
|
179
|
-
return queryData(param, config, true);
|
|
202
|
+
return await queryData(param, config, true);
|
|
180
203
|
}
|
|
181
204
|
|
|
182
205
|
export function getConfig(config) {
|
|
183
206
|
return (Array.isArray(config)) ? config[0] : config;
|
|
184
207
|
}
|
|
185
208
|
|
|
186
|
-
export function loadCliScript(selectedConfig,
|
|
209
|
+
export async function loadCliScript(selectedConfig, column, value) {
|
|
187
210
|
const config = getConfig(selectedConfig);
|
|
188
211
|
|
|
189
|
-
return queryDataPromise(config,
|
|
212
|
+
return await queryDataPromise(config, column, value);
|
|
190
213
|
}
|
|
191
214
|
|
|
192
215
|
export function getInputData(config, trigger) {
|
|
@@ -212,7 +235,8 @@ export function getInputData(config, trigger) {
|
|
|
212
235
|
|
|
213
236
|
export async function scheduleSubscription(config, data, trigger, needSetHistory, isTest = false) {
|
|
214
237
|
try {
|
|
215
|
-
let functions = extractFunctionScript(data);
|
|
238
|
+
let functions = extractFunctionScript(config, data);
|
|
239
|
+
|
|
216
240
|
if (functions) {
|
|
217
241
|
if (!isTest) { // next, change isTest to test better
|
|
218
242
|
functions.onInit(getInputData(config, trigger));
|
|
@@ -235,7 +259,7 @@ export async function scheduleSubscription(config, data, trigger, needSetHistory
|
|
|
235
259
|
|
|
236
260
|
export async function checkSchedule(selectedConfig, trigger, needSetHistory) {
|
|
237
261
|
try {
|
|
238
|
-
const data = await loadCliScript(selectedConfig, trigger);
|
|
262
|
+
const data = await loadCliScript(selectedConfig, 'ID', trigger.scriptid);
|
|
239
263
|
await scheduleSubscription(selectedConfig, data, trigger, needSetHistory);
|
|
240
264
|
} catch (error) {
|
|
241
265
|
console.error(error);
|
package/tests/app.test.js
CHANGED
|
@@ -294,7 +294,7 @@ describe('Biz-A Apps CLI', ()=>{
|
|
|
294
294
|
expect(logSpy.mock.calls[0][0]).toBe('===================\nA.JS\n===================')
|
|
295
295
|
|
|
296
296
|
expect(errorSpy.mock.calls.length).toBe(1)
|
|
297
|
-
expect(errorSpy.mock.calls[0][0]).
|
|
297
|
+
expect(errorSpy.mock.calls[0][0]).toStrictEqual({e: 'a.js:1:38: SyntaxError: Unexpected token: eof, expected: punc «}»'})
|
|
298
298
|
}
|
|
299
299
|
],
|
|
300
300
|
[
|
|
@@ -305,11 +305,11 @@ describe('Biz-A Apps CLI', ()=>{
|
|
|
305
305
|
expect(logSpy.mock.calls[0][0]).toBe('===================\nA.JS\n===================')
|
|
306
306
|
expect(logSpy.mock.calls[1][0]).toBe('Minify : \nget=function(){return{modelA:{}}};modul.expor=get;')
|
|
307
307
|
expect(logSpy.mock.calls[2][0]).toBe('Running script with VM') // node sandbox (VN) error as console.log
|
|
308
|
-
expect(logSpy.mock.calls[3][0]).toBe(
|
|
308
|
+
expect(logSpy.mock.calls[3][0]).toBe("a.js : ReferenceError: modul is not defined")
|
|
309
309
|
expect(logSpy.mock.calls[4][0]).toBe('Running script with Import function')
|
|
310
310
|
|
|
311
311
|
expect(errorSpy.mock.calls.length).toBe(1)
|
|
312
|
-
expect(errorSpy.mock.calls[0][0]).
|
|
312
|
+
expect(errorSpy.mock.calls[0][0]).toStrictEqual({e: 'a.js : ReferenceError: modul is not defined'}) // ES6 import error
|
|
313
313
|
}
|
|
314
314
|
],
|
|
315
315
|
[
|
|
@@ -323,7 +323,7 @@ describe('Biz-A Apps CLI', ()=>{
|
|
|
323
323
|
expect(logSpy.mock.calls[3][0]).toBe('Running script with Import function')
|
|
324
324
|
|
|
325
325
|
expect(errorSpy.mock.calls.length).toBe(1)
|
|
326
|
-
expect(errorSpy.mock.calls[0][0]).
|
|
326
|
+
expect(errorSpy.mock.calls[0][0]).toStrictEqual({e: 'a.js : Failed to compile template script.\nPlease make sure the script is correct and not returning empty result'})
|
|
327
327
|
}
|
|
328
328
|
],
|
|
329
329
|
]
|
package/tests/callback.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const {
|
|
2
|
-
getInputScript
|
|
2
|
+
getInputScript,
|
|
3
|
+
setDirectHubData
|
|
3
4
|
} = await import('../callbackController.js');
|
|
4
5
|
|
|
5
6
|
describe('callback test', () => {
|
|
@@ -40,5 +41,19 @@ describe('callback test', () => {
|
|
|
40
41
|
});
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
test('get input script', () => {
|
|
45
|
+
const req = {
|
|
46
|
+
query: { 'a': 1 },
|
|
47
|
+
body: { 'b': 2 },
|
|
48
|
+
rawHeaders: ['Abc-Xyz', 'def']
|
|
49
|
+
}
|
|
44
50
|
|
|
51
|
+
expect(setDirectHubData(req)).toStrictEqual({
|
|
52
|
+
body: {
|
|
53
|
+
query: { 'a': 1 },
|
|
54
|
+
body: { 'b': 2 },
|
|
55
|
+
headers: { 'abc-xyz': 'def' }
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
})
|
package/tests/data.test.js
CHANGED
|
@@ -2,20 +2,27 @@ import { jest } from '@jest/globals'
|
|
|
2
2
|
|
|
3
3
|
const mockInsertHistory = jest.fn();
|
|
4
4
|
jest.unstable_mockModule("../scheduler/watcherController.js", () => ({
|
|
5
|
-
insertHistory: mockInsertHistory.mockResolvedValue('OK')
|
|
5
|
+
insertHistory: mockInsertHistory.mockResolvedValue('OK'),
|
|
6
6
|
}))
|
|
7
7
|
|
|
8
|
+
jest.unstable_mockModule('axios', () => { return { default: jest.fn() } })
|
|
9
|
+
let axios = (await import('axios')).default
|
|
10
|
+
|
|
11
|
+
axios.get = jest.fn()
|
|
12
|
+
axios.post = jest.fn()
|
|
13
|
+
|
|
8
14
|
const {
|
|
9
15
|
scheduleSubscription,
|
|
10
16
|
getConfig,
|
|
11
17
|
getInputData,
|
|
12
|
-
|
|
18
|
+
getQueryDataPrmsParameters,
|
|
13
19
|
mapData2Key,
|
|
14
20
|
getUrlApi,
|
|
15
21
|
json2Parameters,
|
|
16
22
|
getUrlAndParam,
|
|
17
23
|
getTableObj,
|
|
18
|
-
options
|
|
24
|
+
options,
|
|
25
|
+
setLibrary
|
|
19
26
|
} = await import('../scheduler/datalib.js');
|
|
20
27
|
|
|
21
28
|
describe('data test', () => {
|
|
@@ -141,13 +148,9 @@ describe('data test', () => {
|
|
|
141
148
|
});
|
|
142
149
|
|
|
143
150
|
test('get query data parameter', () => {
|
|
144
|
-
|
|
145
|
-
scriptid: 12
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
expect(getQueryDataObsParameters(trigger)).toStrictEqual({
|
|
151
|
+
expect(getQueryDataPrmsParameters('ID', 12)).toStrictEqual({
|
|
149
152
|
length: 1,
|
|
150
|
-
filter: [{ junction: '', column: 'ID', operator: '=', value1: '12' }],
|
|
153
|
+
filter: [{ junction: '', column: 'ID', operator: '=', value1: "'12'" }],
|
|
151
154
|
columns: [{ data: "SYS$CLI_SCRIPT.SCRIPT", key: 'script' }]
|
|
152
155
|
});
|
|
153
156
|
});
|
|
@@ -306,5 +309,40 @@ describe('data test', () => {
|
|
|
306
309
|
expect(result).toEqual(expectedResult);
|
|
307
310
|
});
|
|
308
311
|
|
|
312
|
+
test('should set library if any', async () => {
|
|
313
|
+
axios.post.mockResolvedValueOnce(axios.post.mockResolvedValueOnce({
|
|
314
|
+
data: [
|
|
315
|
+
{
|
|
316
|
+
'SYS$CLI_SCRIPT.SCRIPT': 'get = function () {\n' +
|
|
317
|
+
' return {\n' +
|
|
318
|
+
' functions: {\n' +
|
|
319
|
+
' yyy: function (data) {\n' +
|
|
320
|
+
' function doit() {\n' +
|
|
321
|
+
' return {\n' +
|
|
322
|
+
" abc: function () { return 'abc'; console.log('abc') },\n" +
|
|
323
|
+
' }\n' +
|
|
324
|
+
' }\n' +
|
|
325
|
+
' return doit()\n' +
|
|
326
|
+
' },\n' +
|
|
327
|
+
' zzz: function () {\n' +
|
|
328
|
+
" return 'aaabbbccc';\n" +
|
|
329
|
+
' }\n' +
|
|
330
|
+
' }\n' +
|
|
331
|
+
' }\n' +
|
|
332
|
+
'}'
|
|
333
|
+
}
|
|
334
|
+
]
|
|
335
|
+
}))
|
|
336
|
+
|
|
337
|
+
const config = {};
|
|
338
|
+
const libraries = ['lib'];
|
|
339
|
+
|
|
340
|
+
const result = await setLibrary(config, libraries);
|
|
341
|
+
|
|
342
|
+
expect(result.lib.yyy().abc()).toStrictEqual('abc');
|
|
343
|
+
expect(result.lib.zzz()).toStrictEqual('aaabbbccc');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
|
|
309
347
|
})
|
|
310
348
|
|