Skip to content

Commit

Permalink
Merge 6a369da into 954e6bf
Browse files Browse the repository at this point in the history
  • Loading branch information
romulogarofalo committed Apr 15, 2020
2 parents 954e6bf + 6a369da commit 048db0b
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/resources/Outbound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

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

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

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

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

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

transformResponseData: transformResponseData,
}),

create: telnyxMethod({
method: 'POST',

transformResponseData: transformResponseData,
}),

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

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

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


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

var TEST_AUTH_KEY = utils.getUserTelnyxKey();

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

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

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

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

it('Sends the correct request', function() {
return telnyx.outboundVoiceProfiles.create({billing_group_id: '6a09cdc3-8948-47f0-aa62-74ac943d6c58', concurrent_call_limit: 10})
.then(responseFn);
})

it('Sends the correct request [with specified auth]', function() {
return telnyx.outboundVoiceProfiles.create({billing_group_id: '6a09cdc3-8948-47f0-aa62-74ac943d6c58', concurrent_call_limit: 10}, TEST_AUTH_KEY)
.then(responseFn);
});

it('Sends the correct request [with specified auth in options]', function() {
return telnyx.outboundVoiceProfiles.create({billing_group_id: '6a09cdc3-8948-47f0-aa62-74ac943d6c58', concurrent_call_limit: 10}, {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.have.property('name');
expect(response.data[0]).to.have.property('billing_group_id');
expect(response.data[0]).to.include({record_type: 'outbound_voice_profile'});
}

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

it('Sends the correct request [with specified auth]', function() {
return telnyx.outboundVoiceProfiles.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: 'outbound_voice_profile'});
}
}

it('Sends the correct request', function() {
return telnyx.outboundVoiceProfiles.create({billing_group_id: '6a09cdc3-8948-47f0-aa62-74ac943d6c58'})
.then(function(response) {
const outboundVoiceProfiles = response.data;
return outboundVoiceProfiles.del()
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.outboundVoiceProfiles.retrieve('123')
.then(function(response) {
const outboundVoiceProfiles = response.data;
return outboundVoiceProfiles.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({concurrent_call_limit: 12});
}
}

it('Sends the correct request', function() {
return telnyx.outboundVoiceProfiles.create({billing_group_id: '6a09cdc3-8948-47f0-aa62-74ac943d6c58', concurrent_call_limit: 10})
.then(function(response) {
const ip = response.data;
return ip.update({billing_group_id: '6a09cdc3-8948-47f0-aa62-74ac943d6c59' ,concurrent_call_limit: 12})
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.outboundVoiceProfiles.retrieve('123')
.then(function(response) {
const ip = response.data;
return ip.update({concurrent_call_limit: 12}, TEST_AUTH_KEY)
.then(responseFn);
})
});
});
});

0 comments on commit 048db0b

Please sign in to comment.