Skip to content

Commit

Permalink
phone numbers inbound channels endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
romulogarofalo committed Apr 14, 2020
1 parent 863ecb2 commit ee083cb
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/resources/PhoneNumbersInboundChannels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

var TelnyxResource = require('../TelnyxResource');
var utils = require('../utils');
var telnyxMethod = TelnyxResource.method;

function transformResponseData(response, telnyx) {
return utils.addResourceToResponseData(
response,
telnyx,
'phoneNumbersInboundChannels',
{
update: telnyxMethod({
method: 'PATCH',
path: '',
urlParams: ['channels'],
paramsValues: [response.data.id],
paramsNames: ['channels'],
}),
}
);
}

module.exports = require('../TelnyxResource').extend({
path: 'phone_numbers/inbound_channels',

retrieve: telnyxMethod({
method: 'GET',
path: '',
urlParams: [],

transformResponseData: transformResponseData,
}),
});
1 change: 1 addition & 0 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var resources = {
Actions: require('./resources/Actions'),
OutboundVoiceProfiles: require('./resources/Outbound'),
CallControlApplications: require('./resources/CallControlApplications'),
PhoneNumbersInboundChannels: require('./resources/PhoneNumbersInboundChannels')
};

Telnyx.TelnyxResource = require('./TelnyxResource');
Expand Down
48 changes: 48 additions & 0 deletions test/resources/PhoneNumberInboundChannels.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

var utils = require('../../testUtils');
var telnyx = utils.getTelnyxMock();
var expect = require('chai').expect;

var TEST_AUTH_KEY = utils.getUserTelnyxKey();

describe('Phone Numbers Inbound Channels', function() {
describe('retrieve', function() {
function responseFn(response) {
expect(response.data).to.include({
record_type: 'inbound_channels',
});
}

it('Sends the correct request', function() {
return telnyx.phoneNumbersInboundChannels.retrieve()
.then(responseFn);
});

it('Sends the correct request [with specified auth]', function() {
return telnyx.phoneNumbersInboundChannels.retrieve(TEST_AUTH_KEY)
.then(responseFn)
});
});

describe('update', function() {
function responseFn(response) {
if (response.data) {
// eslint-disable-next-line no-console
console.log('response', response);
expect(response.data).to.include({channels: 7});
expect(response.data).to.include({record_type: 'inbound_channels'});
}
}

it('Sends the correct request', function() {
return telnyx.phoneNumbersInboundChannels.update({channels: 8})
.then(responseFn);
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.phoneNumbersInboundChannels.update({channels: 8}, TEST_AUTH_KEY)
.then(responseFn);
});
})

});

0 comments on commit ee083cb

Please sign in to comment.