Skip to content

Commit

Permalink
Merge pull request #10 from isocroft/patch-2
Browse files Browse the repository at this point in the history
fix: fixed sendSMS url endpoint path
  • Loading branch information
stitchng authored Dec 15, 2021
2 parents 44bdd6d + 0246894 commit a89b73b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<a name="0.1.0"></a>
# 0.1.0 (2021-12-15)

#### Bug Fixes
- Fixed incorrect SMS Delivery endpoint URL path

<a name="0.1.0-alpha.1"></a>
# 0.1.0-alpha.1 (2021-05-13)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
46 changes: 23 additions & 23 deletions src/InfoBip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
)
Expand All @@ -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 ||
Expand All @@ -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')
}
}
}
}
Expand All @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion test/infobip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit a89b73b

Please sign in to comment.