Skip to content

Commit

Permalink
Merge 7e78c1c into ceff8f7
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa authored Dec 13, 2019
2 parents ceff8f7 + 7e78c1c commit b9fd4b4
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/resources/FqdnConnections.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,
'fqdnConnections',
{
del: telnyxMethod({
method: 'DELETE',
path: '/{fqdnConnectionId}',
urlParams: ['fqdnConnectionId'],
paramsValues: [response.data.id],
paramsNames: ['id'],
}),

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

module.exports = TelnyxResource.extend({
path: 'fqdn_connections',

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 @@ -50,6 +50,7 @@ var resources = {
SimCards: require('./resources/SimCards'),
BillingGroups: require('./resources/BillingGroups'),
IpConnections: require('./resources/IpConnections'),
FqdnConnections: require('./resources/FqdnConnections'),
Actions: require('./resources/Actions'),
};

Expand Down
113 changes: 113 additions & 0 deletions test/resources/FqdnConnections.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
'use strict';

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

var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo';

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

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

it('Sends the correct request [with specified auth]', function() {
return telnyx.fqdnConnections.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('connection_name');
expect(response.data).to.have.property('record_type');
expect(response.data).to.include({connection_name: 'Central BSD-1', record_type: 'fqdn_connection'});
}

it('Sends the correct request', function() {
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'})
.then(responseFn);
})

it('Sends the correct request [with specified auth]', function() {
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'}, TEST_AUTH_KEY)
.then(responseFn);
});

it('Sends the correct request [with specified auth in options]', function() {
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'}, {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('connection_name');
expect(response.data[0]).to.include({record_type: 'fqdn_connection'});
}

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

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

describe('Nested', function() {
function responseFn(response) {
if (response.data) {
expect(response.data).to.have.property('id');
expect(response.data).to.have.property('connection_name');
expect(response.data).to.include({record_type: 'fqdn_connection'});
}
}

describe('del', function() {
it('Sends the correct request', function() {
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'})
.then(function(response) {
const mp = response.data;
return mp.del()
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.fqdnConnections.retrieve('123')
.then(function(response) {
const mp = response.data;
return mp.del(TEST_AUTH_KEY)
.then(responseFn);
})
});
});

describe('update', function() {
it('Sends the correct request', function() {
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'})
.then(function(response) {
const mp = response.data;
return mp.update({connection_name: 'Western BSD-2'})
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.fqdnConnections.retrieve('123')
.then(function(response) {
const mp = response.data;
return mp.update({connection_name: 'Western BSD-2'}, TEST_AUTH_KEY)
.then(responseFn);
})
});
});
})
});

0 comments on commit b9fd4b4

Please sign in to comment.