Skip to content

Commit

Permalink
Merge pull request #80 from ramey-plivo/feature-powerpack
Browse files Browse the repository at this point in the history
Feature powerpack
  • Loading branch information
Abhishek-plivo authored Aug 14, 2018
2 parents 46eec0c + 0e2a805 commit d8122bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
28 changes: 23 additions & 5 deletions lib/resources/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 10 additions & 3 deletions test/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
});

Expand Down

0 comments on commit d8122bf

Please sign in to comment.