From d08f06df0cef6107aa449e01f7e65f1e57db269f Mon Sep 17 00:00:00 2001 From: Ramey Girdhar Date: Tue, 14 Aug 2018 09:31:49 +0530 Subject: [PATCH] powerpack change --- lib/resources/messages.js | 28 +++++++++++++++++++++++----- test/messages.js | 13 ++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/resources/messages.js b/lib/resources/messages.js index fef9ae67..4942dede 100644 --- a/lib/resources/messages.js +++ b/lib/resources/messages.js @@ -69,22 +69,40 @@ export class MessageInterface extends PlivoResourceInterface { * @promise {object} return {@link PlivoGenericMessage} object if success * @fail {Error} return Error */ - create(src, dst, text, optionalParams) { + create(src, dst, text, optionalParams, powerpackUUID) { let errors = validate([ - {field: 'src', value: src, validators: ['isRequired']}, {field: 'dst', value: dst, validators: ['isRequired']}, - {field: 'text', value: text, validators: ['isRequired']} + {field: 'text', value: text, validators: ['isRequired']}, ]); if (errors) { return errors; } + if (!src && !powerpackUUID) { + let errorText = 'Neither of src or powerpack uuid present, either one is required' + return new Promise(function(resolve, reject) { + reject(new Error(errorText)); + }); + } + + if (src && powerpackUUID) { + let errorText = 'Either of src or powerpack uuid, both of them are present' + return new Promise(function(resolve, reject) { + reject(new Error(errorText)); + }) + } + let params = optionalParams || {}; - params.src = src; + if (src) { + params.src = src; + } params.dst = _.isArray(dst) ? _.join(dst, '<') : dst; params.text = text; - + if (powerpackUUID) { + params.powerpackUUID = powerpackUUID; + } + console.log(params) return super.create(params); } diff --git a/test/messages.js b/test/messages.js index b24f4eaf..121f38d0 100644 --- a/test/messages.js +++ b/test/messages.js @@ -42,10 +42,17 @@ describe('message', function () { }) }); - it('should throw error - src is required via interface', function () { - return client.messages.send(null, 'dst', 'text') + it('should throw error - src and powerpack both not present', function () { + return client.messages.send(null, 'dst', 'text', {}, null) .catch(function(err){ - assert.equal(err.message, 'Missing mandatory field: src') + assert.equal(err.message, 'Neither of src or powerpack uuid present, either one is required') + }) + }); + + it('should throw error - src and powerpack both are present', function () { + return client.messages.send('91235456917375', 'dst', 'text', {}, '916386027476') + .catch(function(err){ + assert.equal(err.message, 'Either of src or powerpack uuid, both of them are present') }) });