Skip to content

Commit

Permalink
SMS-6061 adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KaushikDas-Plivo committed Jul 26, 2023
1 parent e908ab8 commit 9223f53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/resources/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class MessageInterface extends PlivoResourceInterface {
* @param {string} [optionalParams.method] The method used to call the url. Defaults to POST.
* @param {boolean} [optionalParams.log] If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
* @param {Array} [optionalParams.media_urls] For sending mms, specify the media urls in list of string
* @param {Template} [optionalParams.template] //add desc
* @param {Template} [optionalParams.template] //For sending templated whatsapp messages
* @promise {object} return {@link PlivoGenericMessage} object if success
* @fail {Error} return Error
*/
Expand Down Expand Up @@ -276,7 +276,7 @@ export class MessageInterface extends PlivoResourceInterface {
}

if ((params.type === 'whatsapp') && !src){
let errorText = 'Src parameter not present'
let errorText = 'src parameter not present'
return new Promise(function(resolve, reject) {
reject(new Error(errorText));
});
Expand Down
14 changes: 14 additions & 0 deletions test/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ describe('message', function () {
})
});

it('should throw error - src parameter not present', function () {
return client.messages.create({src:null, dst:'dst', text:'text',type:'whatsapp', powerpackUUID:'916386027476'})
.catch(function (err) {
assert.equal(err.message, 'src parameter not present')
})
});

it('should throw error - Template paramater is only applicable when message_type is whatsapp', function () {
return client.messages.create({src:'91235456917375', dst:'dst', text:'text',type:'sms',template: {name: "plivo_verification", language: "en_US",}, powerpackUUID:null})
.catch(function (err) {
assert.equal(err.message, 'Template paramater is only applicable when message_type is whatsapp')
})
});

it('should list media via plivo interface!', function (done) {
client.messages.listMedia('xyz')
.then(function (mmsMedia) {
Expand Down

0 comments on commit 9223f53

Please sign in to comment.