From 3c8cbd97c5461ed8ee5c91be8ed79038284c6ca6 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Thu, 1 Jun 2023 21:20:25 +0700 Subject: [PATCH] fix: app_json is applied to outbound call (#173) --- lib/routes/api/accounts.js | 1 + test/call-test.js | 70 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/lib/routes/api/accounts.js b/lib/routes/api/accounts.js index db569f4..ffbd6f5 100644 --- a/lib/routes/api/accounts.js +++ b/lib/routes/api/accounts.js @@ -263,6 +263,7 @@ async function validateCreateCall(logger, sid, req) { const application = await lookupAppBySid(obj.application_sid); Object.assign(obj, { call_hook: application.call_hook, + app_json: application.app_json, call_status_hook: application.call_status_hook, speech_synthesis_vendor: application.speech_synthesis_vendor, speech_synthesis_language: application.speech_synthesis_language, diff --git a/test/call-test.js b/test/call-test.js index 4ba27ea..898e636 100644 --- a/test/call-test.js +++ b/test/call-test.js @@ -83,4 +83,74 @@ test('Create Call Success Without Synthesizer in Payload', async (t) => { } }).then(data => { t.ok(false, 'Create Call should not be success') }) .catch(error => { t.ok(error.response.statusCode === 400, 'Call failed for no synthesizer') }); +}); + +test("Create call with application sid and app_json", async(t) => { + const app = require('../app'); + + const service_provider_sid = await createServiceProvider(request, 'account3_has_synthesizer'); + const account_sid = await createAccount(request, service_provider_sid, 'account3_has_synthesizer'); + + const token = jwt.sign({ + account_sid, + scope: "account", + permissions: ["PROVISION_USERS", "PROVISION_SERVICES", "VIEW_ONLY"] + }, process.env.JWT_SECRET, { expiresIn: '1h' }); + const authUser = { bearer: token }; + const speech_sid = await createGoogleSpeechCredentials(request, account_sid, null, authUser, true, true); + + // GIVEN +/* add an application */ + +const app_json = '[\ + {\ + "verb": "play",\ + "url": "https://example.com/example.mp3",\ + "timeoutSecs": 10,\ + "seekOffset": 8000,\ + "actionHook": "/play/action"\ +}\ +]'; +let result = await request.post('/Applications', { + resolveWithFullResponse: true, + auth: authUser, + json: true, + body: { + name: 'daveh', + account_sid, + call_hook: { + url: 'http://example.com' + }, + call_status_hook: { + url: 'http://example.com/status', + method: 'POST' + }, + messaging_hook: { + url: 'http://example.com/sms' + }, + app_json + } +}); +t.ok(result.statusCode === 201, 'successfully created application'); +const sid = result.body.sid; + +// WHEN +result = await request.post(`/Accounts/${account_sid}/Calls`, { + resolveWithFullResponse: true, + auth: authUser, + json: true, + body: { + application_sid: sid, + from: "15083778299", + to: { + type: "phone", + number: "15089084809" + }, + } +}); +// THEN +t.ok(result.statusCode === 201, 'successfully created Call without Synthesizer && application_sid'); +const fs_request = await getLastRequestFromFeatureServer('15083778299_createCall'); +const obj = JSON.parse(fs_request); +t.ok(obj.body.app_json == app_json, 'app_json successfully added') }); \ No newline at end of file