Skip to content

Commit a89b73b

Browse files
authored
Merge pull request #10 from isocroft/patch-2
fix: fixed sendSMS url endpoint path
2 parents 44bdd6d + 0246894 commit a89b73b

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<a name="0.1.0"></a>
2+
# 0.1.0 (2021-12-15)
3+
4+
#### Bug Fixes
5+
- Fixed incorrect SMS Delivery endpoint URL path
6+
17
<a name="0.1.0-alpha.1"></a>
28
# 0.1.0-alpha.1 (2021-05-13)
39

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "infobip-nodejs",
3-
"version": "0.1.0-alpha.1",
3+
"version": "0.1.0",
44
"description": "A NodeJS Wrapper for InfoBip",
55
"main": "index.js",
66
"files": [

src/InfoBip/index.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ const setPathName = (config, values) => {
9393
offset) {
9494
let _value = values[string]
9595
return isTypeOf(
96-
_value,
97-
config.route_params[string]
96+
config.route_params[string],
97+
_value
9898
)
99-
? _value
99+
? config.route_params[string]
100100
: null
101101
})
102102
}
@@ -313,8 +313,7 @@ class InfoBip extends Mockable {
313313

314314
let reqVerb = config.method.toLowerCase()
315315

316-
return this._mock !== null ? this._mock['sendSMSBinary'].bind(this, params) : got[reqVerb].bind(
317-
got,
316+
return this._mock !== null ? this._mock['sendSMSBinary'].bind(this, params) : got[reqVerb](
318317
`${this.baseUrl}${pathname}`,
319318
this.httpConfig
320319
)
@@ -324,9 +323,9 @@ class InfoBip extends Mockable {
324323
let config = {
325324
send_json: true,
326325
method: 'POST',
327-
path: '/sms/2/text/advanced',
328-
route_params: null,
329-
params: { messages$: Array, bulkId: String }
326+
path: '/sms/2/text/{:type}',
327+
route_params: { type: typeof params.messages === 'undefined' ? 'single' : 'advanced' },
328+
params: { messages: Array, bulkId: String, from: String, to: String, text: String, type: String }
330329
}
331330

332331
if (config.route_params !== null ||
@@ -339,22 +338,24 @@ class InfoBip extends Mockable {
339338
let payload = setInputValues(config, params)
340339
let pathname = setPathName(config, params)
341340

342-
for (let messageIndex in params.messages) {
343-
if (params.messages.hasOwnProperty(messageIndex)) {
344-
let message = params.messages[messageIndex] || []
345-
let destinations = message.destinations || []
341+
if (params.messages) {
342+
for (let messageIndex in params.messages) {
343+
if (params.messages.hasOwnProperty(messageIndex)) {
344+
let message = params.messages[messageIndex] || []
345+
let destinations = message.destinations || []
346346

347-
if (!isTypeOf(message.from, ['string']) ||
348-
!isTypeOf(message.text, ['string'])) {
349-
throw new TypeError('infobip api: request payload for [from, text]; sendSMS() not of correct type')
350-
}
347+
if (!isTypeOf(message.from, ['string']) ||
348+
!isTypeOf(message.text, ['string'])) {
349+
throw new TypeError('infobip api: request payload for [from, text]; sendSMS() not of correct type')
350+
}
351351

352-
for (let destinationIndex in destinations) {
353-
if (destinations.hasOwnProperty(destinationIndex)) {
354-
let destination = destinations[destinationIndex] || {}
352+
for (let destinationIndex in destinations) {
353+
if (destinations.hasOwnProperty(destinationIndex)) {
354+
let destination = destinations[destinationIndex] || {}
355355

356-
if (!isTypeOf(destination.to, ['array', 'string'])) {
357-
throw new TypeError('infobip api: request payload for [to]; SMS not of correct type')
356+
if (!isTypeOf(destination.to, ['array', 'string'])) {
357+
throw new TypeError('infobip api: request payload for [to]; SMS not of correct type')
358+
}
358359
}
359360
}
360361
}
@@ -379,8 +380,7 @@ class InfoBip extends Mockable {
379380

380381
let reqVerb = config.method.toLowerCase()
381382

382-
return this._mock !== null ? this._mock['sendSMS'].bind(this, params) : got[reqVerb].bind(
383-
got,
383+
return this._mock !== null ? this._mock['sendSMS'].bind(this, params) : got[reqVerb](
384384
`${this.baseUrl}${pathname}`,
385385
this.httpConfig
386386
)

test/infobip.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('InfoBip Instance Test(s)', function () {
2323

2424
it('should throw an error if [send] method is called without required arguments', function () {
2525
try {
26-
instance.send()
26+
instance.sendSMS()
2727
} catch (err) {
2828
should.exist(err)
2929
}

0 commit comments

Comments
 (0)