From 70891ab17cf03a81f31a470806cc3bca6ac3cd13 Mon Sep 17 00:00:00 2001 From: Ifeora Okechukwu Date: Sun, 12 Dec 2021 15:18:41 +0100 Subject: [PATCH 1/2] fix: fixed sendSMS url endpoint path --- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/InfoBip/index.js | 46 ++++++++++++++++++++++---------------------- test/infobip.test.js | 2 +- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97c24b9..a1d3c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ + +# 0.1.0- (2021-12-13) + +#### Bug Fixes +- Fixed incorrect SMS Delivery endpoint URL path + # 0.1.0-alpha.1 (2021-05-13) diff --git a/package.json b/package.json index 9bd877a..877b508 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "infobip-nodejs", - "version": "0.1.0-alpha.1", + "version": "0.1.0", "description": "A NodeJS Wrapper for InfoBip", "main": "index.js", "files": [ diff --git a/src/InfoBip/index.js b/src/InfoBip/index.js index a80f5d4..3d48ab3 100644 --- a/src/InfoBip/index.js +++ b/src/InfoBip/index.js @@ -93,10 +93,10 @@ const setPathName = (config, values) => { offset) { let _value = values[string] return isTypeOf( - _value, - config.route_params[string] + config.route_params[string], + _value ) - ? _value + ? config.route_params[string] : null }) } @@ -313,8 +313,7 @@ class InfoBip extends Mockable { let reqVerb = config.method.toLowerCase() - return this._mock !== null ? this._mock['sendSMSBinary'].bind(this, params) : got[reqVerb].bind( - got, + return this._mock !== null ? this._mock['sendSMSBinary'].bind(this, params) : got[reqVerb]( `${this.baseUrl}${pathname}`, this.httpConfig ) @@ -324,9 +323,9 @@ class InfoBip extends Mockable { let config = { send_json: true, method: 'POST', - path: '/sms/2/text/advanced', - route_params: null, - params: { messages$: Array, bulkId: String } + path: '/sms/2/text/{:type}', + route_params: { type: typeof params.messages === 'undefined' ? 'single' : 'advanced' }, + params: { messages: Array, bulkId: String, from: String, to: String, text: String, type: String } } if (config.route_params !== null || @@ -339,22 +338,24 @@ class InfoBip extends Mockable { let payload = setInputValues(config, params) let pathname = setPathName(config, params) - for (let messageIndex in params.messages) { - if (params.messages.hasOwnProperty(messageIndex)) { - let message = params.messages[messageIndex] || [] - let destinations = message.destinations || [] + if (params.messages) { + for (let messageIndex in params.messages) { + if (params.messages.hasOwnProperty(messageIndex)) { + let message = params.messages[messageIndex] || [] + let destinations = message.destinations || [] - if (!isTypeOf(message.from, ['string']) || - !isTypeOf(message.text, ['string'])) { - throw new TypeError('infobip api: request payload for [from, text]; sendSMS() not of correct type') - } + if (!isTypeOf(message.from, ['string']) || + !isTypeOf(message.text, ['string'])) { + throw new TypeError('infobip api: request payload for [from, text]; sendSMS() not of correct type') + } - for (let destinationIndex in destinations) { - if (destinations.hasOwnProperty(destinationIndex)) { - let destination = destinations[destinationIndex] || {} + for (let destinationIndex in destinations) { + if (destinations.hasOwnProperty(destinationIndex)) { + let destination = destinations[destinationIndex] || {} - if (!isTypeOf(destination.to, ['array', 'string'])) { - throw new TypeError('infobip api: request payload for [to]; SMS not of correct type') + if (!isTypeOf(destination.to, ['array', 'string'])) { + throw new TypeError('infobip api: request payload for [to]; SMS not of correct type') + } } } } @@ -379,8 +380,7 @@ class InfoBip extends Mockable { let reqVerb = config.method.toLowerCase() - return this._mock !== null ? this._mock['sendSMS'].bind(this, params) : got[reqVerb].bind( - got, + return this._mock !== null ? this._mock['sendSMS'].bind(this, params) : got[reqVerb]( `${this.baseUrl}${pathname}`, this.httpConfig ) diff --git a/test/infobip.test.js b/test/infobip.test.js index a029cdf..6cfd757 100644 --- a/test/infobip.test.js +++ b/test/infobip.test.js @@ -23,7 +23,7 @@ describe('InfoBip Instance Test(s)', function () { it('should throw an error if [send] method is called without required arguments', function () { try { - instance.send() + instance.sendSMS() } catch (err) { should.exist(err) } From 02468948949f00b4cb3f33eafa63b722a71d7ee8 Mon Sep 17 00:00:00 2001 From: StitchNG Date: Wed, 15 Dec 2021 13:54:09 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1d3c80..0d9093b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ - -# 0.1.0- (2021-12-13) + +# 0.1.0 (2021-12-15) #### Bug Fixes - Fixed incorrect SMS Delivery endpoint URL path