mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-30 06:12:08 -06:00
powerpack change
This commit is contained in:
parent
46eec0caa8
commit
d08f06df0c
2 changed files with 33 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue