Skip to content

Commit

Permalink
feat(resources): add Ips and Fqdns Resources (#25)
Browse files Browse the repository at this point in the history
* add Ips Resource

* add Fqdns Resource

* target new telnyx-mock version
  • Loading branch information
lucasassisrosa committed Jan 30, 2020
1 parent 406df79 commit 92b4ee0
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cache:
env:
global:
# If changing this number, please also look it at tests config.
- TELNYX_MOCK_VERSION=0.7.3
- TELNYX_MOCK_VERSION=0.8.0

before_install:
# Unpack and start telnyx-mock so that the test suite can talk to it
Expand Down
55 changes: 55 additions & 0 deletions lib/resources/Fqdns.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,
'fqdns',
{
del: telnyxMethod({
method: 'DELETE',
path: '/{fqdnId}',
urlParams: ['fqdnId'],
paramsValues: [response.data.id],
paramsNames: ['id'],
}),

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

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

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

transformResponseData: transformResponseData,
}),

create: telnyxMethod({
method: 'POST',

transformResponseData: transformResponseData,
}),

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

transformResponseData: transformResponseData,
}),
});
55 changes: 55 additions & 0 deletions lib/resources/Ips.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,
'ips',
{
del: telnyxMethod({
method: 'DELETE',
path: '/{ipId}',
urlParams: ['ipId'],
paramsValues: [response.data.id],
paramsNames: ['id'],
}),

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

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

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

transformResponseData: transformResponseData,
}),

create: telnyxMethod({
method: 'POST',

transformResponseData: transformResponseData,
}),

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

transformResponseData: transformResponseData,
}),
});
2 changes: 2 additions & 0 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var resources = {
PublicKey: require('./resources/PublicKey'),
SimCards: require('./resources/SimCards'),
BillingGroups: require('./resources/BillingGroups'),
Ips: require('./resources/Ips'),
Fqdns: require('./resources/Fqdns'),
IpConnections: require('./resources/IpConnections'),
FqdnConnections: require('./resources/FqdnConnections'),
CredentialConnections: require('./resources/CredentialConnections'),
Expand Down
116 changes: 116 additions & 0 deletions test/resources/Fqdns.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
'use strict';

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

var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo';

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

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

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

it('Sends the correct request', function() {
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'})
.then(responseFn);
})

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

it('Sends the correct request [with specified auth in options]', function() {
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'}, {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_id');
expect(response.data).to.have.property('fqdn');
expect(response.data[0]).to.include({record_type: 'fqdn'});
}

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

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

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

describe('update', function() {
it('Sends the correct request', function() {
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'})
.then(function(response) {
const fqdn = response.data;
return fqdn.update({connection_id: 'Western BSD-2'})
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.fqdns.retrieve('123')
.then(function(response) {
const fqdn = response.data;
return fqdn.update({connection_id: 'Western BSD-2'}, TEST_AUTH_KEY)
.then(responseFn);
})
});
});
})
});
16 changes: 8 additions & 8 deletions test/resources/IpConnections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ describe('IpConnections Resource', function() {
it('Sends the correct request', function() {
return telnyx.ipConnections.create({connection_name: 'Central BSD-1'})
.then(function(response) {
const mp = response.data;
return mp.del()
const ipConnection = response.data;
return ipConnection.del()
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.ipConnections.retrieve('123')
.then(function(response) {
const mp = response.data;
return mp.del(TEST_AUTH_KEY)
const ipConnection = response.data;
return ipConnection.del(TEST_AUTH_KEY)
.then(responseFn);
})
});
Expand All @@ -95,16 +95,16 @@ describe('IpConnections Resource', function() {
it('Sends the correct request', function() {
return telnyx.ipConnections.create({connection_name: 'Central BSD-1'})
.then(function(response) {
const mp = response.data;
return mp.update({connection_name: 'Western BSD-2'})
const ipConnection = response.data;
return ipConnection.update({connection_name: 'Western BSD-2'})
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.ipConnections.retrieve('123')
.then(function(response) {
const mp = response.data;
return mp.update({connection_name: 'Western BSD-2'}, TEST_AUTH_KEY)
const ipConnection = response.data;
return ipConnection.update({connection_name: 'Western BSD-2'}, TEST_AUTH_KEY)
.then(responseFn);
})
});
Expand Down
Loading

0 comments on commit 92b4ee0

Please sign in to comment.