Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resources): add Ips and Fqdns Resources #25

Merged
merged 3 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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