From 702948715d3508a599e09b0cc39317c3a3d92d62 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Thu, 27 Jul 2023 21:59:47 +0700 Subject: [PATCH] fix customerdata should not be snakeCase --- lib/session/call-info.js | 2 +- lib/tasks/rest_dial.js | 2 +- lib/utils/http-requestor.js | 2 +- package.json | 2 +- test/create-call-test.js | 11 +++++++++-- test/say-tests.js | 18 ++++++++++++++++++ 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/session/call-info.js b/lib/session/call-info.js index a87bb63d..f15c1765 100644 --- a/lib/session/call-info.js +++ b/lib/session/call-info.js @@ -144,7 +144,7 @@ class CallInfo { if (typeof this.duration === 'number') obj.duration = this.duration; if (this._customerData) { - Object.assign(obj, {customerData: this._customerData}); + Object.assign(obj, {customerdata: this._customerData}); } if (JAMBONES_API_BASE_URL) { diff --git a/lib/tasks/rest_dial.js b/lib/tasks/rest_dial.js index 40b87555..d64bb3b2 100644 --- a/lib/tasks/rest_dial.js +++ b/lib/tasks/rest_dial.js @@ -68,7 +68,7 @@ class TaskRestDial extends Task { const b3 = this.getTracingPropagation(); const httpHeaders = b3 && {b3}; const params = { - ...cs.callInfo, + ...cs.callInfo.toJSON(), defaults: { synthesizer: { vendor: cs.speechSynthesisVendor, diff --git a/lib/utils/http-requestor.js b/lib/utils/http-requestor.js index ce7a5916..4e523605 100644 --- a/lib/utils/http-requestor.js +++ b/lib/utils/http-requestor.js @@ -87,7 +87,7 @@ class HttpRequestor extends BaseRequestor { assert(HookMsgTypes.includes(type)); - const payload = params ? snakeCaseKeys(params, ['sip']) : null; + const payload = params ? snakeCaseKeys(params, ['customerdata', 'sip']) : null; const url = hook.url || hook; const method = hook.method || 'POST'; let buf = ''; diff --git a/package.json b/package.json index 6131c345..67612f48 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "bugs": {}, "scripts": { "start": "node app", - "test": "NODE_ENV=test JAMBONES_HOSTING=1 HTTP_POOL=1 JAMBONES_TTS_TRIM_SILENCE=1 ENCRYPTION_SECRET=foobar DRACHTIO_HOST=127.0.0.1 DRACHTIO_PORT=9060 DRACHTIO_SECRET=cymru JAMBONES_MYSQL_HOST=127.0.0.1 JAMBONES_MYSQL_PORT=3360 JAMBONES_MYSQL_USER=jambones_test JAMBONES_MYSQL_PASSWORD=jambones_test JAMBONES_MYSQL_DATABASE=jambones_test JAMBONES_REDIS_HOST=127.0.0.1 JAMBONES_REDIS_PORT=16379 JAMBONES_LOGLEVEL=error ENABLE_METRICS=0 HTTP_PORT=3000 JAMBONES_SBCS=172.38.0.10 JAMBONES_FREESWITCH=127.0.0.1:8022:JambonzR0ck$:docker-host JAMBONES_TIME_SERIES_HOST=127.0.0.1 JAMBONES_NETWORK_CIDR=172.38.0.0/16 node test/ ", + "test": "NODE_ENV=test JAMBONES_HOSTING=1 HTTP_POOL=1 JAMBONES_TTS_TRIM_SILENCE=1 ENCRYPTION_SECRET=foobar DRACHTIO_HOST=127.0.0.1 DRACHTIO_PORT=9060 DRACHTIO_SECRET=cymru JAMBONES_MYSQL_HOST=127.0.0.1 JAMBONES_MYSQL_PORT=3360 JAMBONES_MYSQL_USER=jambones_test JAMBONES_MYSQL_PASSWORD=jambones_test JAMBONES_MYSQL_DATABASE=jambones_test JAMBONES_REDIS_HOST=127.0.0.1 JAMBONES_REDIS_PORT=16379 JAMBONES_LOGLEVEL=debug ENABLE_METRICS=0 HTTP_PORT=3000 JAMBONES_SBCS=172.38.0.10 JAMBONES_FREESWITCH=127.0.0.1:8022:JambonzR0ck$:docker-host JAMBONES_TIME_SERIES_HOST=127.0.0.1 JAMBONES_NETWORK_CIDR=172.38.0.0/16 node test/ ", "coverage": "./node_modules/.bin/nyc --reporter html --report-dir ./coverage npm run test", "jslint": "eslint app.js tracer.js lib", "jslint:fix": "eslint app.js tracer.js lib --fix" diff --git a/test/create-call-test.js b/test/create-call-test.js index a6d7a6b8..7de8cd4d 100644 --- a/test/create-call-test.js +++ b/test/create-call-test.js @@ -80,6 +80,10 @@ test('test create-call call-hook basic authentication', async(t) => { "username": "username", "password": "password" }, + "call_status_hook": { + "url": "http://127.0.0.1:3100/callStatus", + "method": "POST" + }, "tag": { "callCount": 10, "env": "DEVELOPMENT", @@ -106,11 +110,14 @@ test('test create-call call-hook basic authentication', async(t) => { await p; let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}`); - console.log(obj); t.ok(obj.headers.Authorization = 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'create-call: call-hook contains basic authentication header'); - t.ok(obj.body.customerdata.callCount = 10, + t.ok(obj.body.customerdata.callCount === 10, 'create-call: call-hook contains correct format for customerData'); + + obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}_callStatus`); + t.ok(obj.body.customerdata.callCount === 10, + 'create-call: call-hook contains correct format for customerData'); disconnect(); } catch (err) { console.log(`error received: ${err}`); diff --git a/test/say-tests.js b/test/say-tests.js index 84f96efb..a77fea37 100644 --- a/test/say-tests.js +++ b/test/say-tests.js @@ -2,6 +2,8 @@ const test = require('tape'); const { sippUac } = require('./sipp')('test_fs'); const clearModule = require('clear-module'); const {provisionCallHook} = require('./utils') +const bent = require('bent'); +const getJSON = bent('json') process.on('unhandledRejection', (reason, p) => { console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); @@ -27,6 +29,18 @@ test('\'say\' tests', async(t) => { { verb: 'say', text: 'hello' + }, + { + verb: "tag", + data: { + callCount: 10, + env: "DEVELOPMENT", + processId: "processId", + Customer: "Customer", + Vehicle: "Vehicle", + Event_Camel: "Event_Camel", + CamelCase: "CamelCase" + } } ]; @@ -36,6 +50,10 @@ test('\'say\' tests', async(t) => { // THEN await sippUac('uac-success-received-bye.xml', '172.38.0.10', from); t.pass('say: succeeds when using using account credentials'); + let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}_callStatus`); + console.log(obj); + t.ok(obj.body.customerdata.callCount === 10, + 'create-call: call-hook contains correct format for customerData'); disconnect(); } catch (err) { console.log(`error received: ${err}`);