Skip to content

Commit

Permalink
Merge branch 'master' of github.com:team-telnyx/telnyx-node
Browse files Browse the repository at this point in the history
  • Loading branch information
romulogarofalo committed Apr 20, 2020
2 parents bf33752 + 27b4579 commit 8a383e9
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 1 deletion.
54 changes: 54 additions & 0 deletions lib/resources/CallControlApplications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

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

function transformResponseData(response, telnyx) {
return utils.addResourceToResponseData(
response,
telnyx,
'callControlApplications',
{
del: telnyxMethod({
method: 'DELETE',
path: '/{callControlId}',
urlParams: ['callControlId'],
paramsValues: [response.data.id],
paramsNames: ['id'],
}),

update: telnyxMethod({
method: 'PATCH',
path: '/{callControlId}',
urlParams: ['callControlId'],
paramsValues: [response.data.id],
paramsNames: ['id'],
}),
}
);
}

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

list: telnyxMethod({
method: 'GET',
methodType: 'list',

transformResponseData: transformResponseData,
}),

create: telnyxMethod({
method: 'POST',
transformResponseData: transformResponseData,
}),

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

transformResponseData: transformResponseData,
}),
});
3 changes: 2 additions & 1 deletion lib/resources/PhoneNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = require('../TelnyxResource').extend({

nestedResources: {
Messaging: require('./PhoneNumbersMessaging'),
Voice: require('./PhoneNumbersVoice')
Voice: require('./PhoneNumbersVoice'),
Inbound: require('./PhoneNumbersInboundChannels'),
},

retrieveVoiceSettings: telnyxMethod({
Expand Down
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,
}),
});
2 changes: 2 additions & 0 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var resources = {
NumberOrderDocuments: require('./resources/NumberOrderDocuments'),
Actions: require('./resources/Actions'),
OutboundVoiceProfiles: require('./resources/Outbound'),
CallControlApplications: require('./resources/CallControlApplications'),
PhoneNumbersInboundChannels: require('./resources/PhoneNumbersInboundChannels')
};

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


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

var TEST_AUTH_KEY = utils.getUserTelnyxKey();

describe('Call Control List list', function() {
describe('retrieve', function() {
function responseFn(response) {
expect(response.data).to.include({id: '123'});
}

it('Sends the correct request', function() {
return telnyx.callControlApplications.retrieve('123').then((response) => {
responseFn(response)
});
})

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

describe('create', function() {
function responseFn(response) {
expect(response.data).to.have.property('id');
expect(response.data).to.include({record_type: 'call_control_application'});
}

it('Sends the correct request', function() {
return telnyx.callControlApplications.create({'application_name': 'test', 'webhook_event_url': '123123'})
.then(responseFn);
})

it('Sends the correct request [with specified auth]', function() {
return telnyx.callControlApplications.create({'application_name': 'test', 'webhook_event_url': '123123'}, TEST_AUTH_KEY)
.then(responseFn);
});

it('Sends the correct request [with specified auth in options]', function() {
return telnyx.callControlApplications.create({'application_name': 'test', 'webhook_event_url': '123123'}, {api_key: TEST_AUTH_KEY})
.then(responseFn);
});
});

describe('list', function() {
function responseFn(response) {
expect(response.data[0]).to.have.property('id');
expect(response.data[0]).to.include({record_type: 'call_control_application'});
}

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

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

describe('del', function() {

function responseFn(response) {
if (response.data) {
expect(response.data).to.have.property('id');
expect(response.data).to.include({record_type: 'call_control_application'});
}
}

it('Sends the correct request', function() {
return telnyx.callControlApplications.create({'application_name': 'test', 'webhook_event_url': '123123'})
.then(function(response) {
const callControlApplications = response.data;
return callControlApplications.del()
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.callControlApplications.retrieve('123')
.then(function(response) {
const callControlApplications = response.data;
return callControlApplications.del(TEST_AUTH_KEY)
.then(responseFn);
})
});
});

describe('update', function() {
function responseFn(response) {
if (response.data) {
expect(response.data).to.have.property('id');
expect(response.data).to.include({application_name: 'test updated'});
}
}

it('Sends the correct request', function() {
return telnyx.callControlApplications.create({'application_name': 'test', 'webhook_event_url': '123123'})
.then(function(response) {
const ip = response.data;
return ip.update({'application_name': 'test updated', 'webhook_event_url': '123123'})
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.callControlApplications.retrieve('123')
.then(function(response) {
const ip = response.data;
return ip.update({'application_name': 'test updated', 'webhook_event_url': '123123'}, TEST_AUTH_KEY)
.then(responseFn);
})
});
});
});
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 8a383e9

Please sign in to comment.