diff --git a/TODO b/TODO deleted file mode 100644 index d89e100..0000000 --- a/TODO +++ /dev/null @@ -1,9 +0,0 @@ -How to validate languages with voice - -Male female voices for polly+voice combination - -Promise, chain will break - -Will childs be there in ssml for validation? - -If Polly.* provided, is language validation required? \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index cec03d2..f272484 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -45,7 +45,7 @@ gulp.task('test', ['pre-test'], function (cb) { console.log('Running tests with node version', process.version); - gulp.src('test/**/ssml.js') + gulp.src('test/**/*.js') .pipe(plumber()) .pipe(mocha({ reporter: 'spec' })) .on('error', function (err) { diff --git a/lib/rest/utils.js b/lib/rest/utils.js index 863b506..e8fd419 100644 --- a/lib/rest/utils.js +++ b/lib/rest/utils.js @@ -59,11 +59,14 @@ export function validateVoiceForSsml(content, voice, language) { return new Promise(function (resolve, reject) { - var voiceParts = voice.split('.'); - if (['MAN', 'WOMAN'].indexOf(voice) != -1) { + + if (!voice || ['MAN', 'WOMAN'].indexOf(voice) != -1) { resolve({ success: true }); return; - } else if (voiceParts.length != 2 || voiceParts[0] != 'Polly') { + } + + var voiceParts = voice.split('.'); + if (voiceParts.length != 2 || voiceParts[0] != 'Polly') { resolve({ success: false, msg: "Invalid voice " + voice + '.' }); diff --git a/lib/utils/plivoxml.js b/lib/utils/plivoxml.js index 35ea35c..4177b5d 100644 --- a/lib/utils/plivoxml.js +++ b/lib/utils/plivoxml.js @@ -270,22 +270,18 @@ Response.prototype = { } body = newBody; - // If attributes not provided, use empty dictionary - if (!attributes) { - attributes = {}; - } - // Validate voice first. - if (!attributes.voice) { - attributes.voice = 'WOMAN'; + let voice = null, language = null; + if (attributes && attributes.voice) { + voice = attributes.voice; } - if (!attributes.language) { - attributes.language = 'English'; + if (attributes && attributes.language) { + language = attributes.language; } var item = this; return new Promise(function (resolve, reject) { - plivoUtils.validateVoiceForSsml(body, attributes.voice, attributes.language).then(function (ssmlValidationResult) { + plivoUtils.validateVoiceForSsml(body, voice, language).then(function (ssmlValidationResult) { // console.log('result...', ssmlValidationResult); if (ssmlValidationResult.success == true) { var result = item.add(new Speak(Response), body, attributes); diff --git a/test/ssml.js b/test/ssml.js index 9cc1645..ee68a06 100644 --- a/test/ssml.js +++ b/test/ssml.js @@ -1,31 +1,10 @@ import assert from 'assert'; import { Response, Client } from '../lib/rest/client'; import { PlivoGenericResponse } from '../lib/base.js'; - let client = new Client('sampleid', 'sammpletoken', 'sampleproxy'); describe('SsmlInterface', function () { - it('Ssml - Valid XML', function (done) { - - let response = new Response(); - - // Valid speak body - let speak_body = ' Here is a number read \ - as a cardinal number: \ - klsdjflksjfsldk. \ - Here is a word spelled out: \ - hello.'; - - // response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.*' }); - response.addSpeak(speak_body, { language: 'Spanish-Castilian', voice: 'Polly.Conchita' }).then((result) => { - done(); - }).catch((err) => { - done("Valid SSML xml should not be rejected."); - }); - - }); - it('Ssml - Invalid SSML XML Structure', function (done) { let response = new Response(); diff --git a/test/xml.js b/test/xml.js index 6061b81..efb2b60 100644 --- a/test/xml.js +++ b/test/xml.js @@ -3,26 +3,30 @@ import sinon from 'sinon'; import { Response } from '../lib/utils/plivoxml'; describe('PlivoXML', function () { - it('should work', function () { + it('should work', function (done) { const response = new Response(); response.addPreAnswer(); response.addRecord(); response.addHangup(); - response.addSpeak('text'); - response.addWait(); - response.addDTMF('123'); - response.addConference('test'); - response.addRedirect('url'); - response.addGetDigits(); - response.addPlay('url'); - const dial = response.addDial(); - dial.addNumber('123'); + response.addSpeak('text').then(function (result) { + response.addWait(); + response.addDTMF('123'); + response.addConference('test'); + response.addRedirect('url'); + response.addGetDigits(); + response.addPlay('url'); + const dial = response.addDial(); + dial.addNumber('123'); - dial.addUser('sip:test@sip.plivo.com'); - response.addMessage('∫test', { - src: '123', - dst: '456', + dial.addUser('sip:test@sip.plivo.com'); + response.addMessage('∫test', { + src: '123', + dst: '456', + }); + assert.equal('text123testurlurl123sip:test@sip.plivo.com∫test', response.toXML()); + done(); + }).catch(function (err) { + done("Failed to test Plivo Xml due to unknown error"); }); - assert.equal('text123testurlurl123sip:test@sip.plivo.com∫test', response.toXML()); }); });